Created
May 26, 2011 13:55
-
-
Save pencilcheck/993193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import pi, sin, cos | |
from direct.showbase.ShowBase import ShowBase | |
from direct.task import Task | |
from direct.actor.Actor import Actor | |
from direct.interval.IntervalGlobal import Sequence | |
from panda3d.core import Point3 | |
from pandac.PandaModules import * | |
class MyApp(ShowBase): | |
def __init__(self): | |
ShowBase.__init__(self) | |
# Disable camera trackball controls | |
#self.disableMouse() | |
# Load environment model | |
self.environ = self.loader.loadModel("/Developer/Panda3D/models/environment") | |
# Reparent the model to render | |
self.environ.reparentTo(self.render) | |
# Apply scale and position transforms on the model | |
self.environ.setScale(0.25, 0.25, 0.25) | |
self.environ.setPos(-8, 24, 0) | |
# Add the spinCameraTask | |
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask") | |
# Load and transform the panda actor | |
self.pandaActor = Actor("/Developer/Panda3D/models/panda-model", {"walk4": "/Developer/Panda3D/models/panda-walk4"}) | |
self.pandaActor.setScale(0.015, 0.015, 0.015) | |
self.pandaActor.reparentTo(self.render) | |
# Loop animation | |
self.pandaActor.loop("walk4") | |
# Create intervals | |
pandaPosInterval1 = self.pandaActor.posInterval(13, | |
Point3(0, -10, 0), | |
startPos=Point3(0, 10, 0)) | |
pandaPosInterval2 = self.pandaActor.posInterval(13, | |
Point3(0, 10, 0), | |
startPos=Point3(0, -10, 0)) | |
pandaHprInterval1 = self.pandaActor.hprInterval(3, | |
Point3(180, 0, 0), | |
startHpr=Point3(0, 0, 0)) | |
pandaHprInterval2 = self.pandaActor.hprInterval(3, | |
Point3(0, 0, 0), | |
startHpr=Point3(180, 0, 0)) | |
# Play sequence that coordinates the intervals | |
self.pandaPace = Sequence(pandaPosInterval1, | |
pandaHprInterval1, | |
pandaPosInterval2, | |
pandaHprInterval2, | |
name="pandaPace") | |
# Lighting | |
dlight = DirectionalLight('my dlight') | |
#dlight.setColor(VBase4(0.8, 0.8, 0.5, 1)) | |
dlnp = self.render.attachNewNode(dlight) | |
dlnp.setHpr(0, -60, 0) | |
slight = Spotlight('my slight') | |
slight.setColor(VBase4(1, 1, 1, 1)) | |
lens = PerspectiveLens() | |
slight.setLens(lens) | |
slnp = self.render.attachNewNode(slight) | |
slnp.setPos(100, 200, 0) | |
slnp.lookAt(self.pandaActor) | |
# turn on shadow | |
#slight.setShadowCaster(True, 512, 512) | |
dlight.setShadowCaster(True, 512, 512) | |
self.render.setShaderAuto() | |
# turn on lighting effect for the world | |
#render.setLight(slnp) | |
self.render.setLight(dlnp) | |
self.pandaPace.loop() | |
def spinCameraTask(self, task): | |
angleDegrees = task.time * 6.0 | |
angleRadians = angleDegrees * (pi / 180.0) | |
self.camera.setPos(50 * sin(angleRadians), -50.0 * cos(angleRadians), 3) | |
self.camera.setHpr(angleDegrees, 0, 0) | |
return Task.cont | |
app = MyApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment