Пример #1
0
def process(hoxlist, getgeom, drawpiece,withstyle=True):
    glPushMatrix()
    try:
        for h in hoxlist:
            if not h: continue  # all nothings are NOOPs
            if type(h) is tuple:
                op = h[0]
                if op == DRAW or (op == STYLE and withstyle):
                    drawpiece(h[1])
                elif op == MOVE:
                    try:    #debug
                        op,name,axis,mult = h
                    except ValueError:  #debug
                        print h #debug
                        raise   #debug
                    t = getgeom(name)
                    if not t: continue  # skip the rest if zero movement
                    v = [0.0,0.0,0.0]
                    v[axis] = t * mult
                    glTranslatef(*v)
                elif op == ROT:
                    try:    #debug
                        op,name,axis,mult = h
                    except ValueError:  #debug
                        print h #debug
                        raise   #debug
                    a = getgeom(name)
                    if not a: continue  # skip the rest if zero rotation
                    v = [0.0,0.0,0.0]
                    v[axis] = 1.0
                    glRotatef(a * mult,*v)
            else:   # recurse into sub-list
                process(h,getgeom,drawpiece,withstyle)
    finally:
        glPopMatrix()   # GOT to do this no matter what!
Пример #2
0
def process(hoxlist, getgeom, drawpiece, withstyle=True):
    glPushMatrix()
    try:
        for h in hoxlist:
            if not h: continue  # all nothings are NOOPs
            if type(h) is tuple:
                op = h[0]
                if op == DRAW or (op == STYLE and withstyle):
                    drawpiece(h[1])
                elif op == MOVE:
                    try:  #debug
                        op, name, axis, mult = h
                    except ValueError:  #debug
                        print h  #debug
                        raise  #debug
                    t = getgeom(name)
                    if not t: continue  # skip the rest if zero movement
                    v = [0.0, 0.0, 0.0]
                    v[axis] = t * mult
                    glTranslatef(*v)
                elif op == ROT:
                    try:  #debug
                        op, name, axis, mult = h
                    except ValueError:  #debug
                        print h  #debug
                        raise  #debug
                    a = getgeom(name)
                    if not a: continue  # skip the rest if zero rotation
                    v = [0.0, 0.0, 0.0]
                    v[axis] = 1.0
                    glRotatef(a * mult, *v)
            else:  # recurse into sub-list
                process(h, getgeom, drawpiece, withstyle)
    finally:
        glPopMatrix()  # GOT to do this no matter what!
Пример #3
0
 def setup_geom(self):
     """Default setup_geom is translation to pos, rotation by angle"""
     pos = self.pos
     angle = self.angle
     glPushMatrix()
     glTranslatef(*pos)
     if angle:
         glRotatef(angle,0,0,1.0)
Пример #4
0
 def setup_geom(self):
     """Default setup_geom is translation to pos, rotation by angle"""
     pos = self.pos
     angle = self.angle
     glPushMatrix()
     glTranslatef(*pos)
     if angle:
         glRotatef(angle, 0, 0, 1.0)
Пример #5
0
import gl

def vec(*args):
    return (GLfloat * len(args))(*args)

def sphere(radius, slices, stacks):
    q = gluNewQuadric();
    gluQuadricNormals(q, GLU_SMOOTH);
    gluSphere(q, radius, slices, stacks);
    gluDeleteQuadric(q);



w = 400
h = 400

osmesa.init_ctx(w, h)
osmesa.render()

gl.glPushMatrix()
gl.glTranslatef(-10.0, 10.0, 0)
osmesa.sphere(20)
gl.glPopMatrix()

gl.glPushMatrix()
gl.glTranslatef(-10.0, 10.0, 0)
osmesa.sphere(22)
gl.glPopMatrix()

osmesa.free_ctx()