From: Ricardo K. <ric...@gm...> - 2005-10-27 22:38:38
|
Hi: I am really new to this ode/pyode thing. I am trying to develop a simulatio= n using pyode. I finally made it (using several "borrowed example code" :-)) to have my objects get rendered on screen. They are currently generated a bit above the ground, so when I rendered them, they fall a little (inspired by the pyode tutorial2). I have created = a model that consists of two boxes that should be connected through a stick. All three objects get correctly rendered, but they don't keep together (the= y just split apart as soon as they fall on the ground) The code I am using to created those objects is: ---------------------------------------------------------------------------= -------------------------------------------- def create_box(world, space, density, lx, ly, lz): """Create a box body and its corresponding geom.""" # Create body body =3D ode.Body(world) M =3D ode.Mass() M.setBox(density, lx, ly, lz) body.setMass(M) # Set parameters for drawing the body body.shape =3D "box" body.boxsize =3D (lx, ly, lz) # Create a box geom for collision detection geom =3D ode.GeomBox(space, lengths=3Dbody.boxsize) geom.setBody(body) return body def drop_object(): """Drop an object into the scene.""" global bodies blockA =3D create_box(world, space, 1000, 1.0,1.0,1.0) blockB =3D create_box(world, space, 1000, 1.0,1.0,1.0) link =3D create_box(world, space, 1000, 1.0, 0.2, 0.2) x, y, z =3D 0.0, 1.0, 0.0 blockA.setPosition( (x,y,z )) link.setPosition((x+1,y,z)) blockB.setPosition((x+2,y,z)) m =3D mat4().rotation(0, (0,1,0)) blockA.setRotation(m.toList()) blockB.setRotation(m.toList()) link.setRotation(m.toList()) j1 =3D ode.HingeJoint(world) j2 =3D ode.HingeJoint(world) j1.attach(blockA, link) j2.attach(blockB, link) j1.setAnchor((0,0,0)) j2.setAnchor((1,0,0)) j1.setAxis((0,0,1)) j2.setAxis((0,0,1)) j1.setParam(ode.ParamFMax, ode.Infinity) j1.setParam(ode.ParamVel, 0) j2.setParam(ode.ParamFMax, ode.Infinity) j2.setParam(ode.ParamVel, 0) bodies.append(blockA) bodies.append(blockB) bodies.append(link) ---------------------------------------------------------------------------= -------------------------------------------- Maybe someone can help me to get this three objects remain connected all time? Maybe I should have written to the ode mailing list, but since I am writing code in python, I thought of this one. With regards, Ricardo Kirkner |
From: Paul K. <pki...@in...> - 2005-10-27 22:48:07
|
From memory - you need to keep a global copy of your joint (since pyode doesn't store them). Your joints are potentially being destroyed when drop_object() exists. Paul -----Original Message----- From: pyo...@li... [mailto:pyo...@li...] On Behalf Of Ricardo Kirkner Sent: Friday, 28 October 2005 8:08 AM To: pyo...@li... Subject: [Pyode-user] General question about ode Hi: I am really new to this ode/pyode thing. I am trying to develop a simulation using pyode. I finally made it (using several "borrowed example code" :-)) to have my objects get rendered on screen. They are currently generated a bit above the ground, so when I rendered them, they fall a little (inspired by the pyode tutorial2). I have created a model that consists of two boxes that should be connected through a stick. All three objects get correctly rendered, but they don't keep together (they just split apart as soon as they fall on the ground) The code I am using to created those objects is: ------------------------------------------------------------------------ ----------------------------------------------- def create_box(world, space, density, lx, ly, lz): """Create a box body and its corresponding geom.""" # Create body body = ode.Body(world) M = ode.Mass() M.setBox(density, lx, ly, lz) body.setMass(M) # Set parameters for drawing the body body.shape = "box" body.boxsize = (lx, ly, lz) # Create a box geom for collision detection geom = ode.GeomBox(space, lengths=body.boxsize) geom.setBody(body) return body def drop_object(): """Drop an object into the scene.""" global bodies blockA = create_box(world, space, 1000, 1.0,1.0,1.0) blockB = create_box(world, space, 1000, 1.0,1.0,1.0) link = create_box(world, space, 1000, 1.0, 0.2, 0.2) x, y, z = 0.0, 1.0, 0.0 blockA.setPosition( (x,y,z )) link.setPosition((x+1,y,z)) blockB.setPosition((x+2,y,z)) m = mat4().rotation(0, (0,1,0)) blockA.setRotation(m.toList()) blockB.setRotation(m.toList()) link.setRotation(m.toList()) j1 = ode.HingeJoint(world) j2 = ode.HingeJoint(world) j1.attach(blockA, link) j2.attach(blockB, link) j1.setAnchor((0,0,0)) j2.setAnchor((1,0,0)) j1.setAxis((0,0,1)) j2.setAxis((0,0,1)) j1.setParam(ode.ParamFMax, ode.Infinity) j1.setParam(ode.ParamVel, 0) j2.setParam(ode.ParamFMax, ode.Infinity) j2.setParam(ode.ParamVel, 0) bodies.append(blockA) bodies.append(blockB) bodies.append(link) ------------------------------------------------------------------------ ----------------------------------------------- Maybe someone can help me to get this three objects remain connected all time? Maybe I should have written to the ode mailing list, but since I am writing code in python, I thought of this one. With regards, Ricardo Kirkner |