Пример #1
0
def draw(self, texID=None, n=None):
    texToUse = None
    if texID != None:
        texToUse = texID
    elif n != None:
        n = n % (len(self.textureList))
        i = 0
        for t in self.textureList:
            if i == n:
                texToUse = self.textureList[t]["texID"]
                break
            i += 1

    mtrx = matrix()
    mtrx.push()
    transform(
        self.x, self.y, self.z, self.rotx, self.roty, self.rotz, self.sx, self.sy, self.sz, self.cx, self.cy, self.cz
    )
    for g in self.vGroup:
        opengles.glShadeModel(GL_SMOOTH)
        opengles.glVertexPointer(3, GL_FLOAT, 0, self.vGroup[g]["vertices"])
        opengles.glNormalPointer(GL_FLOAT, 0, self.vGroup[g]["normals"])

        if texToUse > 0:
            texture_on(texToUse, self.vGroup[g]["tex_coords"], GL_FLOAT)
        elif self.vGroup[g]["texID"] > 0:
            texture_on(self.vGroup[g]["texID"], self.vGroup[g]["tex_coords"], GL_FLOAT)

        # TODO enable material colours as well as textures from images
        if self.vGroup[g]["material"] != None:
            # opengles.glMaterialfv(GL_FRONT, GL_DIFFUSE, self.vGroup[g]["material"]);
            opengles.glEnableClientState(GL_COLOR_ARRAY)
            opengles.glColorPointer(4, GL_UNSIGNED_BYTE, 0, self.vGroup[g]["material"])

        opengles.glDrawElements(
            GL_TRIANGLES, self.vGroup[g]["trianglesLen"], GL_UNSIGNED_SHORT, self.vGroup[g]["triangles"]
        )

        if self.vGroup[g]["texID"] > 0:
            texture_off()
        opengles.glShadeModel(GL_FLAT)
    mtrx.pop()

    for c in self.childModel:
        relx, rely, relz = c.x, c.y, c.z
        relrotx, relroty, relrotz = c.rotx, c.roty, c.rotz
        rval = rotateVec(self.rotx, self.roty, self.rotz, (c.x, c.y, c.z))
        c.x, c.y, c.z = self.x + rval[0], self.y + rval[1], self.z + rval[2]
        c.rotx, c.roty, c.rotz = self.rotx + c.rotx, self.roty + c.roty, self.rotz + c.rotz
        c.draw()  # should texture override be passed down to children?
        c.x, c.y, c.z = relx, rely, relz
        c.rotx, c.roty, c.rotz = relrotx, relroty, relrotz
Пример #2
0
def draw(self, texID=None, n=None):
    texToUse = None
    if texID != None:
        texToUse = texID
    elif n != None:
        n = n % (len(self.textureList))
        i = 0
        for t in self.textureList:
            if i == n:
                texToUse = self.textureList[t]["texID"]
                break
            i += 1

    mtrx = matrix()
    mtrx.push()
    transform(self.x, self.y, self.z, self.rotx, self.roty, self.rotz, self.sx,
              self.sy, self.sz, self.cx, self.cy, self.cz)
    for g in self.vGroup:
        opengles.glShadeModel(GL_SMOOTH)
        opengles.glVertexPointer(3, GL_FLOAT, 0, self.vGroup[g]["vertices"])
        opengles.glNormalPointer(GL_FLOAT, 0, self.vGroup[g]["normals"])

        if texToUse > 0:
            texture_on(texToUse, self.vGroup[g]["tex_coords"], GL_FLOAT)
        elif self.vGroup[g]["texID"] > 0:
            texture_on(self.vGroup[g]["texID"], self.vGroup[g]["tex_coords"],
                       GL_FLOAT)

        #TODO enable material colours as well as textures from images
        if self.vGroup[g]["material"] != None:
            #opengles.glMaterialfv(GL_FRONT, GL_DIFFUSE, self.vGroup[g]["material"]);
            opengles.glEnableClientState(GL_COLOR_ARRAY)
            opengles.glColorPointer(4, GL_UNSIGNED_BYTE, 0,
                                    self.vGroup[g]["material"])

        opengles.glDrawElements(GL_TRIANGLES, self.vGroup[g]["trianglesLen"],
                                GL_UNSIGNED_SHORT, self.vGroup[g]["triangles"])

        if self.vGroup[g]["texID"] > 0: texture_off()
        opengles.glShadeModel(GL_FLAT)
    mtrx.pop()

    for c in self.childModel:
        relx, rely, relz = c.x, c.y, c.z
        relrotx, relroty, relrotz = c.rotx, c.roty, c.rotz
        rval = rotateVec(self.rotx, self.roty, self.rotz, (c.x, c.y, c.z))
        c.x, c.y, c.z = self.x + rval[0], self.y + rval[1], self.z + rval[2]
        c.rotx, c.roty, c.rotz = self.rotx + c.rotx, self.roty + c.roty, self.rotz + c.rotz
        c.draw()  #should texture override be passed down to children?
        c.x, c.y, c.z = relx, rely, relz
        c.rotx, c.roty, c.rotz = relrotx, relroty, relrotz
Пример #3
0
def draw(self, texID=None, n=None, x=0,y=0,z=0, rx=0,ry=0,rz=0, sx=0,sy=0,sz=0, cx=0,cy=0,cz=0):
    texToUse = None
    if texID != None:
         texToUse = texID
    elif n != None:
        n = n % (len(self.textureList))
        i = 0
        sorted_tex = sorted(self.textureList.iteritems(), key=operator.itemgetter(0))
        for t in sorted_tex:
            if i == n:
                texToUse = t[1]["texID"]
                break
            i += 1

    mtrx = matrix()
    mtrx.push()
    transform(self.x+x,self.y+y,self.z+z, self.rotx+rx,self.roty+ry,self.rotz+rz, self.sx+sx,self.sy+sy,self.sz+sz, self.cx+cx,self.cy+cy,self.cz+cz)
    for g in self.vGroup:
        #opengles.glShadeModel(GL_SMOOTH)
        opengles.glVertexPointer( 3, GL_FLOAT, 0, self.vGroup[g].vertices);
        opengles.glNormalPointer( GL_FLOAT, 0, self.vGroup[g].normals);
        
        if texToUse > 0: texture_on(texToUse, self.vGroup[g].tex_coords, GL_FLOAT)
        elif self.vGroup[g].texID > 0: texture_on(self.vGroup[g].texID, self.vGroup[g].tex_coords, GL_FLOAT)
        
        #TODO enable material colours as well as textures from images
        if self.vGroup[g].material != None:
            #opengles.glMaterialfv(GL_FRONT, GL_DIFFUSE, self.vGroup[g].material);
            opengles.glEnableClientState(GL_COLOR_ARRAY)
            opengles.glColorPointer( 4, GL_UNSIGNED_BYTE, 0, self.vGroup[g].material);
        
        opengles.glDrawElements( GL_TRIANGLES, self.vGroup[g].indicesLen, GL_UNSIGNED_SHORT, self.vGroup[g].indices)
        
        if self.vGroup[g].texID > 0: texture_off()
        if self.vGroup[g].material !=None: opengles.glDisableClientState(GL_COLOR_ARRAY)
        #opengles.glShadeModel(GL_FLAT)
    mtrx.pop()
    
    for c in self.childModel:
        relx, rely, relz = c.x+x, c.y+y, c.z+z
        relrotx, relroty, relrotz = c.rotx+rx, c.roty+ry, c.rotz+rz
        rval = rotateVec(self.rotx+rx, self.roty+ry, self.rotz+rz, (c.x, c.y, c.z))
        c.x, c.y, c.z = self.x + x + rval[0], self.y +y + rval[1], self.z + z + rval[2]
        c.rotx, c.roty, c.rotz = self.rotx + rx + c.rotx, self.roty + ry + c.roty, self.rotz + rz + c.rotz
        c.draw() #should texture override be passed down to children?
        c.x, c.y, c.z = relx, rely, relz
        c.rotx, c.roty, c.rotz = relrotx, relroty, relrotz