Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 10th, 2010 | Syntax: Python | Size: 1.72 KB | Hits: 39 | Expires: Never
Copy text to clipboard
  1. from math import pi, sin, cos
  2.  
  3. from direct.showbase.ShowBase import ShowBase
  4. from direct.task import Task
  5. from direct.actor.Actor import Actor
  6.  
  7. class MyApp(ShowBase):
  8.     def __init__(self):
  9.         ShowBase.__init__(self)
  10.  
  11.         # Load the environment model.
  12.         self.environ = self.loader.loadModel("models/environment")
  13.         # Reparent the model to render.
  14.         self.environ.reparentTo(self.render)
  15.         # Apply scale and position transforms on the model.
  16.         self.environ.setScale(0.25, 0.25, 0.25)
  17.         self.environ.setPos(-8, 42, 0)
  18.  
  19.         # Add the spinCameraTask procedure to the task manager.
  20.         self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
  21.  
  22.         # Load and transform the panda actor.
  23.         self.pandaActor = Actor("models/panda-model",
  24.                                 {"walk": "models/panda-walk4"})
  25.         self.pandaActor.setScale(0.005, 0.005, 0.005)
  26.         self.pandaActor.reparentTo(self.render)
  27.         # Loop its animation.
  28.         self.pandaActor.loop("walk")
  29.                
  30.                 # Load and transform the panda actor.
  31.         self.pandaActor2 = Actor("models/panda-model",
  32.                                 {"walk": "models/panda-walk4"})
  33.         self.pandaActor2.setScale(0.005, 0.005, 0.005)
  34.         self.pandaActor2.reparentTo(self.render)
  35.         # Loop its animation.
  36.         self.pandaActor2.loop("walk")
  37.  
  38.     # Define a procedure to move the camera.
  39.     def spinCameraTask(self, task):
  40.         angleDegrees = task.time * 4.0
  41.         angleRadians = angleDegrees * (pi / 180.0)
  42.         self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
  43.         self.camera.setHpr(angleDegrees, 0, 0)
  44.         return Task.cont
  45.  
  46. app = MyApp()
  47. app.run()