cubes that just wont obey gravity

cxxD

30-05-2010 17:57:55

hi,

i've got a problem with making boxes that fall down. if i create them in the createScene function they fall. but if i create them in a seperate class (code below) they wont. what could be a problem?

class Cube():

def __init__(self, world, sceneManager, space):
self.world = world
self.sceneManager = sceneManager
self.space = space

def create(self, x, y, z):
cube = self.sceneManager.createEntity("cube" + str(x) + str(y)+ str(z), "cube.mesh")
cube.castShadows = True
cube.NormaliseNormals = True
cube.setQueryFlags(1<<2)
cubeNode = self.sceneManager.getRootSceneNode().createChildSceneNode("cube" + str(x) + str(y)+ str(z))
cubeNode.setScale(15, 15, 15)
cubeNode.attachObject(cube)

mass = ode.BoxMass(5, (15,15,15))
self.body = ode.Body(self.world)
self.body.setMass(mass)
cubeNode.attachObject(self.body)
geom = ode.BoxGeometry((15, 15, 15), self.world, self.space)
geom.setBody(self.body)
cube.setUserObject(geom)
Application().bodies.append(self.body)
collisionObject = MyCollidingObject()
geom.setUserAny(ogre.Any(collisionObject))
#Application.collisionObjects.append(collisionObject)
self.body.setPosition((x,y,z))

def random(self):
self.create(random.randrange(-600, 600, 10), random.randrange(0, 600, 10), random.randrange(-600, 600, 10))


i think its just me beeing stupid but i hope you can help.

andy

01-06-2010 10:43:43

Have a look at demos/ogreode/SimpleScenes.py for some help -- I'd suggest that you need to keep the geometry around..
self._geoms.append(geom)
What's happening is that geom is going out of scope and being deleted, then your cube doesn't really 'exist' in ODE and hence doesn't fall..

Regards
Andy

cxxD

06-06-2010 16:10:34

this is exactly what i've thought... but i didn't know how to handle it. thanks