コード例 #1
0
ファイル: Model.py プロジェクト: JamesR1/pi3d
  def draw(self, texID=None, n=None):
    # TODO: shadows Shape.draw.
    if self.exf != 'egg' and self.exf != 'obj':
      return

    # From loaderEgg.draw, probably added by paddy gaunt 15 June 2012
    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()
    self.transform()
    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);

      texture = texToUse or self.vGroup[g].texID
      with Texture.Loader(texture, self.vGroup[g].tex_coords):
        #TODO enable material colours as well as textures from images
        material = self.vGroup[g].material
        if material:
          #opengles.glMaterialfv(GL_FRONT, GL_DIFFUSE, material);
          opengles.glEnableClientState(GL_COLOR_ARRAY)
          opengles.glColorPointer(4, GL_UNSIGNED_BYTE, 0, material);

        opengles.glDrawElements(GL_TRIANGLES, self.vGroup[g].indicesLen,
                                GL_UNSIGNED_SHORT, self.vGroup[g].indices)


        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 = rotate_vec(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
ファイル: BuckfastAbbey.py プロジェクト: JamesR1/pi3d
mylight = Light(0,1,1,1,"",0,200,200,0.4,0.4,0.4)
mtrx=Matrix()

omx=mymouse.x
omy=mymouse.y

while 1:
  display.clear()

  mtrx.identity()
  mtrx.rotate(tilt, rot, 0)
  mtrx.translate(xm,ym,zm)
  mtrx.push()
  mtrx.rotate(0, 180, 0)
  myecube.draw(ectex,xm,ym,zm)
  mtrx.pop()

  mylight.on()
  mymodel.draw()
  mylight.off()

  mx=mymouse.x
  my=mymouse.y

  if mx>display.left and mx<display.right and my>display.top and my<display.bottom:
    rot += (mx-omx)*0.5
    tilt -= (my-omy)*0.5
    omx=mx
    omy=my

  #Press ESCAPE to terminate