forked from jwaschkau/ragetracks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ode_test.py
64 lines (50 loc) · 2.01 KB
/
ode_test.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
58
59
60
61
62
63
64
from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import AmbientLight, VBase4, OdeWorld
class RageTracks(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.setFrameRateMeter(True)
# base.disableMouse()
# initialise the lights
alight = AmbientLight('alight')
alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)
# Initialise the Ode world
self.world = OdeWorld()
self.world.setGravity(0, 0, -9.81)
# load the models
# environment
self.environ = self.loader.loadModel("data/models/Plane")
# Reparent the model to render.
self.environ.reparentTo(self.render)
# Apply scale and position transforms on the model.
self.environ.setScale(10, 10, 10)
self.environ.setPos(0, 0, 0)
# racer
self.glider = self.loader.loadModel("data/models/vehicle01")
# Reparent the model to render.
self.glider.reparentTo(self.render)
# Apply scale and position transforms on the model.
self.glider.setScale(1, 1, 1)
self.glider.setPos(0, 0, 50)
self.myBody = OdeBody(self.world)
self.myBody.setPosition(self.glider.getPos(render))
self.myBody.setQuaternion(self.glider.getQuat(render))
self.myMass = OdeMass()
self.myMass.setBox(11340, 1, 1, 1)
self.myBody.setMass(self.myMass)
# set up the camera
base.camera.reparentTo(self.glider)
base.camera.setPos(0, -30, 10)
base.camera.lookAt(self.glider)
# add physics to taskmgr
taskMgr.add(self.physicsTask, 'physics')
def physicsTask(self, task):
# Step the simulation and set the new positions
self.world.quickStep(globalClock.getDt())
# set new positions
self.glider.setPosQuat(render, self.myBody.getPosition(), Quat(self.myBody.getQuaternion()))
return task.cont
game = RageTracks()
game.run()