from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import *
from direct.task.Task import Task
import random
class MyObject:
def __init__(self):
self.node = loader.loadModel("models/ralph").copyTo(render)
self.update()
def update(self):
self.node.setPos(Vec3(random.randint(-10,10),random.randint(-10,10),random.randint(-10,10)))
self.node.setHpr(Vec3(random.randint(-10,10),random.randint(-10,10),random.randint(-10,10)))
print "update"
class MyApp(ShowBase):
def __init__(self,useOdeTriMeshGeom):
ShowBase.__init__(self)
self.objects = {}
self.world = OdeWorld()
self.space = OdeSimpleSpace()
self.contactgroup = OdeJointGroup()
self.bitmask = BitMask32(1)
self.world.initSurfaceTable(1)
self.world.setSurfaceEntry(0, 0, 150, 0.0, 9.1, 0.9, 0.00001, 0.0, 0.002)
self.space.setAutoCollideWorld(self.world)
self.space.setAutoCollideJointGroup(self.contactgroup)
for x in range(10):
self._add_object(MyObject(),useOdeTriMeshGeom)
task = taskMgr.add(self.update, "ViewMission_update")
def update(self,task):
for id, obj in self.objects.items():
#comment in if you want a 'assertion "bNormalizationResult" failed in ../../include\ode/odemath.h:297'
#obj.update()
obj.geom.setPosition(obj.node.getPos(render))
obj.geom.setQuaternion(obj.node.getQuat(render))
self.space.autoCollide()
self.contactgroup.empty()
return Task.cont
def _add_object(self, obj,useTriangle):
body = OdeBody(self.world)
currentobjectid = str(body)
self.objects[currentobjectid] = obj
if useTriangle:
obj.geom = OdeTriMeshGeom(self.space, OdeTriMeshData(obj.node))
obj.geom.setBody(body)
else:
amin, amax = obj.node.getTightBounds()
obj.geom = OdeBoxGeom(self.space, amax - amin)
obj.geom.setBody(body)
obj.geom.setOffsetPosition(-(amin + amax) / 2)
app = MyApp(True)
app.run()