Skip to content

Commit 18a50ca

Browse files
committed
Tutorial Completed
1 parent 3693fd5 commit 18a50ca

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

panda3dtutorial.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
from direct.interval.IntervalGlobal import Sequence
7+
from panda3d.core import Point3
8+
9+
10+
class MyApp(ShowBase):
11+
12+
def __init__(self):
13+
ShowBase.__init__(self)
14+
15+
16+
# Load the environment model.
17+
self.scene = self.loader.loadModel("models/environment")
18+
19+
# Reparent the model to render.
20+
self.scene.reparentTo(self.render)
21+
22+
# Apply scale and position transforms on the model.
23+
self.scene.setScale(0.25, 0.25, 0.25)
24+
self.scene.setPos(-8, 42, 0)
25+
26+
27+
# Add the spinCameraTask procedure to the task manager.
28+
self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
29+
30+
# Load and transform the panda actor.
31+
self.pandaActor = Actor("models/panda-model",
32+
{"walk": "models/panda-walk4"})
33+
self.pandaActor.setScale(0.005, 0.005, 0.005)
34+
self.pandaActor.reparentTo(self.render)
35+
36+
# Loop its animation.
37+
self.pandaActor.loop("walk")
38+
39+
# Create the four lerp intervals needed for the panda to
40+
# walk back and forth.
41+
posInterval1 = self.pandaActor.posInterval(13,
42+
Point3(0, -10, 0),
43+
startPos=Point3(0, 10, 0))
44+
posInterval2 = self.pandaActor.posInterval(13,
45+
Point3(0, 10, 0),
46+
startPos=Point3(0, -10, 0))
47+
hprInterval1 = self.pandaActor.hprInterval(3,
48+
Point3(180, 0, 0),
49+
startHpr=Point3(0, 0, 0))
50+
hprInterval2 = self.pandaActor.hprInterval(3,
51+
Point3(0, 0, 0),
52+
startHpr=Point3(180, 0, 0))
53+
54+
# Create and play the sequence that coordinates the intervals.
55+
self.pandaPace = Sequence(posInterval1, hprInterval1,
56+
posInterval2, hprInterval2,
57+
name="pandaPace")
58+
59+
self.pandaPace.loop()
60+
61+
# Define a procedure to move the camera.
62+
def spinCameraTask(self, task):
63+
angleDegrees = task.time * 6.0
64+
angleRadians = angleDegrees * (pi / 180.0)
65+
self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 3)
66+
self.camera.setHpr(angleDegrees, 0, 0)
67+
return Task.cont
68+
69+
70+
app = MyApp()
71+
app.run()

0 commit comments

Comments
 (0)