-
Notifications
You must be signed in to change notification settings - Fork 0
/
PusherExample.py
57 lines (47 loc) · 2 KB
/
PusherExample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from direct.showbase.ShowBase import ShowBase
from panda3d.core import CollisionTraverser, CollisionHandlerPusher
from panda3d.core import CollisionNode, CollisionSphere
from panda3d.core import Point3
# Initialize the scene.
ShowBase()
# Initialize the collision traverser.
base.cTrav = CollisionTraverser()
# Initialize the Pusher collision handler.
pusher = CollisionHandlerPusher()
# Load a model.
smiley = loader.loadModel('smiley')
# Reparent the model to the camera so we can move it.
smiley.reparentTo(camera)
# Set the initial position of the model in the scene.
smiley.setPos(0, 25.5, 0.5)
# Create a collision node for this object.
cNode = CollisionNode('smiley')
# Attach a collision sphere solid to the collision node.
cNode.addSolid(CollisionSphere(0, 0, 0, 1.1))
# Attach the collision node to the object's model.
smileyC = smiley.attachNewNode(cNode)
# Set the object's collision node to render as visible.
smileyC.show()
# Load another model.
frowney = loader.loadModel('frowney')
# Reparent the model to render.
frowney.reparentTo(render)
# Set the position of the model in the scene.
frowney.setPos(5, 25, 0)
# Create a collision node for this object.
cNode = CollisionNode('frowney')
# Attach a collision sphere solid to the collision node.
cNode.addSolid(CollisionSphere(0, 0, 0, 1.1))
# Attach the collision node to the object's model.
frowneyC = frowney.attachNewNode(cNode)
# Set the object's collision node to render as visible.
frowneyC.show()
# Add the Pusher collision handler to the collision traverser.
base.cTrav.addCollider(frowneyC, pusher)
# Add the 'frowney' collision node to the Pusher collision handler.
pusher.addCollider(frowneyC, frowney, base.drive.node())
# Have the 'smiley' sphere moving to help show what is happening.
frowney.posInterval(5, Point3(5, 25, 0), startPos=Point3(-5, 25, 0), fluid=1).loop()
# Run the scene. Move around with the mouse to see how the moving sphere changes
# course to avoid the one attached to the camera.
run()