Skip to content

Instantly share code, notes, and snippets.

@uxdxdev
Created December 21, 2016 15:15
Show Gist options
  • Save uxdxdev/503d9b3d9a0eb2eadc884aee822881c5 to your computer and use it in GitHub Desktop.
Save uxdxdev/503d9b3d9a0eb2eadc884aee822881c5 to your computer and use it in GitHub Desktop.
Panda3D Moonwalking Panda Source Code
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 *
from panda3d.core import Point3
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.disableMouse();
self.environ = self.loader.loadModel("models/environment");
self.environ.reparentTo(self.render);
self.environ.setScale(0.25, 0.25, 0.25);
self.environ.setPos(-8, 42, 0);
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask");
# Additional code for animations
self.pandaActor = Actor("models/panda-model",
{"walk" : "models/panda-walk4"});
self.pandaActor.setScale(0.005, 0.005, 0.005);
self.pandaActor.reparentTo(self.render);
self.pandaActor.loop("walk");
# Additions for intervals and sequences
pandaPosInterval1 = self.pandaActor.posInterval(1, Point3(0, 10, 0), startPos = Point3(0, 0, 0));
pandaPosInterval2 = self.pandaActor.posInterval(1, Point3(10, 0, 0), startPos = Point3(0, 10, 0));
pandaPosInterval3 = self.pandaActor.posInterval(1, Point3(0, -10, 0), startPos = Point3(10, 0, 0));
pandaPosInterval4 = self.pandaActor.posInterval(1, Point3(-10, 0, 0), startPos = Point3(0, -10, 0));
pandaPosInterval5 = self.pandaActor.posInterval(1, Point3(-10, 0, 0), startPos = Point3(0, -10, 0));
pandaPosInterval6 = self.pandaActor.posInterval(1, Point3(0, 10, 0), startPos = Point3(-10, 0, 0));
pandaPosInterval7 = self.pandaActor.posInterval(1, Point3(0, 0, 0), startPos = Point3(0, 10, 0));
pandaPosInterval8 = self.pandaActor.posInterval(3, Point3(0, 10, 2), startPos = Point3(0, 0, 0));
pandaHprInterval1 = self.pandaActor.hprInterval(1, Point3(180, 0, 0));
pandaHprInterval2 = self.pandaActor.hprInterval(1, Point3(45, 0, 0));
pandaHprInterval3 = self.pandaActor.hprInterval(1, Point3(-45, 0, 0));
pandaHprInterval4 = self.pandaActor.hprInterval(1, Point3(-135, 0, 0));
pandaHprInterval5 = self.pandaActor.hprInterval(1, Point3(-225, 0, 0));
pandaHprInterval6 = self.pandaActor.hprInterval(1, Point3(-360, 0, 0));
pandaHprInterval7 = self.pandaActor.hprInterval(1, Point3(-360, -45, 0));
self.pandaPace = Sequence(pandaHprInterval1, pandaPosInterval1, pandaHprInterval2, pandaPosInterval2, pandaHprInterval3, pandaPosInterval3, pandaHprInterval4, pandaPosInterval5, pandaHprInterval5, pandaPosInterval6, pandaHprInterval6, pandaPosInterval7, Parallel(pandaHprInterval7, pandaPosInterval8), name = "pandaPace").start();
#self.pandaPace.loop();
def spinCameraTask(self, task):
print "task.time: ", task.time;
angleDegrees = task.time * 6.0;
print "angle degrees: ", angleDegrees;
angleRadians = angleDegrees * (pi / 180.0);
print "angle radians: ", angleRadians;
self.camera.setPos(30 * sin(angleRadians), -30.0 * cos(angleRadians), 15);
print "camera position: ", self.camera.getPos();
print 'camera posX: {} camera posY: {}'.format(20.0*sin(angleRadians), -20.0*cos(angleRadians))
self.camera.setHpr(angleDegrees, -20, 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