I am desperate for ODE tutorials

nicolasbrown

10-06-2008 00:59:06

I cant believe that there are no ode tutorials for ogre :cry:
Can any of you 'professionals' make an ode tutorial for me pleeeeeeeeeeeaaaaaaaase. I'm sure it will help everyone else also(newbies to python-ogre like me).
I got the basics of ode, from the pyODE website:
http://pyode.sourceforge.net/
and i looked at the ode tutorials that came with python-ogre,I can only make falling barrels and ogreheads.I tend to catch on to thing easy(else i would be still wondering what a FrameListener is)
Please make it simple so that I can understand(i am just a kid,15).

bharling

10-06-2008 11:12:52

There are plenty of demos using OgreOde in the pythonOgre demos folder, I'd suggest looking at that first. Its probably easier to use OgreOde rather than straight ODE, as the some of the ogre integration is handled for you already.

nicolasbrown

10-06-2008 12:50:15

ok, imma do that.But arent there any tutorials :?:
I am really desperate :cry:

bharling

11-06-2008 21:26:52

A famous search engine suggests:

http://www.ogre3d.org/wiki/index.php/Og ... _Character

http://89.151.96.106/phpBB2addons/viewf ... 6f4e2718c6

http://gpwiki.org/index.php/ODE_Object_tutorial

both of those are for C++ ogre ODE, but its usually easy to translate this into python.

The problem is that Python-Ogre is still quite a new project, yet it already has loads of different components, so there is a lot of catching up to do with the documentation. I agree we need more tutorials, so if you feel like writing one please do :)

nicolasbrown

12-06-2008 01:14:28

thx,i dont think translating will be a problem. :D
I dont think i can write any, i dont have enough experience.
I havent even made a game yet :oops:

bharling

12-06-2008 10:40:22

hey dont worry! I've never *cough* made a game either ... ;)

nicolasbrown

12-06-2008 10:52:29

I am done translating.I gotta use a FrameListener to update the ninja's position(Imma do that later).It took me nearly two hours to finish it.


import ogre.renderer.OGRE as ogre
import SampleFramework as sf
from math import *
import ogre.physics.OgreOde as ode


class TutorialApplication (sf.Application):
def __init__(self):
sf.Application.__init__(self)
self.world = ode.World(self.sceneManager)
self.dollSpace = self.world.getDefaultSpace()
self.dollSpace.setInternalCollisions(False)
self.world.setGravity(ogre.Vector3(0,-9.80665,0))
self.world.setCFM(10e-5)
self.world.setERP(0.8)
self.world.setAutoSleep(True)
self.world.setContactCorrectionVelocity(1.0)

def _createScene (self):
sm = self.sceneManager
sm.ambient = 1,1,1
ninja = sm.createEntity('ninja','ninja.mesh')
ninjanode = sm.rootSceneNode.createChildSceneNode('ninja')
modelnode = ninjanode.createChildSceneNode('model_node')
modelnode.attachObject(ninja)
ninjanode.setScale(0.05,0.05,0.05)

aab = modelnode.getAttachedObject('ninja').getBoundingBox()
mini = aab.getMinimum()*ninjanode.getScale()
maxi = aab.getMaximum()*ninjanode.getScale()
centre = aab.getCenter()*ninjanode.getScale()
print ninjanode.position
size = ogre.Vector3(fabs(maxi.x-mini.x),fabs(maxi.y-mini.y),fabs(maxi.z-mini.z))
if size.x>size.z:
radius = size.z/2.0
else:
radius = size.x/2.0

dollfeetbody = ode.Body(self.world)
dollfeetbody.setMass(ode.SphereMass(70*2.5,radius))
feetGeom = ode.SphereGeometry(radius,self.world)
feetTrans = ode.TransformGeometry(self.world,self.dollSpace)
modelnode.translate(ogre.Vector3(0,-radius/ninjanode.getScale().y,0))
feetTrans.setBody(dollfeetbody)
feetTrans.setEncapsulatedGeometry(feetGeom)
ninjanode.attachObject(dollfeetbody)
self.plane = ode.InfinitePlaneGeometry(ogre.Plane((0,1,0),0),
self.world,
self.world.getDefaultSpace())
s = sm.createStaticGeometry('StaticFloor')
s.setRegionDimensions((160,100,160))
s.setOrigin((0,-100,0))

i = 0
for z in range(-80,80,20):
for x in range(-80,80,20):
name = 'Plane_'+str(i)
i+=1
ent = sm.createEntity(name,'plane.mesh')
ent.setQueryFlags(1<<4)
ent.setUserObject(self.plane)
s.addEntity(ent,ogre.Vector3(x,0,z))
#ent.scale = 0.05,0.05,0.05
s.build()

torso = ode.Body(self.world)
torso.setMass(ode.CapsuleMass(70*2.5,radius,ogre.Vector3.UNIT_Y,radius))
torso.setAffectedByGravity(False)
torso.setDamping(0,50000)
torsoTrans = ode.TransformGeometry(self.world,self.dollSpace)
torsoGeom = ode.CapsuleGeometry(radius,size.y-4*radius,self.world,self.dollSpace)
torsoGeom.setPosition(ogre.Vector3(0,size.y-((size.y-4*radius)/2+2*radius),0))
torsoGeom.setOrientation(ogre.Quaternion(ogre.Degree(90),ogre.Vector3.UNIT_X))
torsoTrans.setBody(torso)
torsoTrans.setEncapsulatedGeometry(torsoGeom)
ninjanode.attachObject(torso)

joint = ode.HingeJoint(self.world)
joint.attach(torso,dollfeetbody)
joint.setAxis(ogre.Vector3.UNIT_X)
max_frame_time = 1.0/4.0

stepModeType = ode.StepHandler.BasicStep
self.stepper = ode.StepHandler(self.world,ode.StepHandler.QuickStep,
0.01,max_frame_time,1.7)
self.stepper.setAutomatic(ode.StepHandler.AutoMode_PostFrame,self.root)

def _createCamera (self):
self.camera = self.sceneManager.createCamera('PlayerCam')
self.camera.position =0,10,-30
self.camera.lookAt((0,0,0))
self.camera.nearClipDistance = 1

def _createViewports (self):
viewport = self.renderWindow.addViewport(self.camera)
viewport.backGroundColor = (0,0,0)
self.camera.aspectRatio = float (viewport.actualWidth) / float (viewport.actualHeight)


if __name__ == '__main__':
ta = TutorialApplication ()
ta.go ()


This thread helped me toohttp://www.ogre3d.org/phpBB2addons/viewtopic.php?t=5949&sid=ce193664e1d3d7c4af509e6f4e2718c6

(how's that for a fifteen year old 8) )

nicolasbrown

13-06-2008 01:01:45

I found a great tutorial at http://www.ogre3d.org/wiki/index.php/First_steps_with_OgreODE
but it is in the C++ Language

here's the finished product(in case you see the code and dont understand it)


import ogre.renderer.OGRE as ogre
import SampleFramework as sf
import ogre.physics.OgreOde as ode
from math import *

class OdeListener(sf.FrameListener):
def __init__(self, renderWindow, camera,world,stepper):
sf.FrameListener.__init__(self, renderWindow, camera)
self.world = world
self.stepper = stepper

def frameStarted(self, frameEvent):
time = 1.0/60.0
self.stepper.step(time)
self.world.synchronise()

return sf.FrameListener.frameStarted(self, frameEvent)
class TutorialApplication (sf.Application):
def __init__(self):
sf.Application.__init__(self)

self.world = ode.World(self.sceneManager)
self.world.setGravity((0,-9.80665,0))
self.world.setCFM(10e-5)
self.world.setERP(0.8)
self.world.setAutoSleep(True)
self.world.setAutoSleepAverageSamplesCount(10)
self.world.setContactCorrectionVelocity(1.0)
self.space = self.world.getDefaultSpace()

def _createScene (self):
sm = self.sceneManager
sm.ambient = 1,1,1
time_step = 0.5
time_scale = 1.7
max_frame_time = 1.0/4
self.stepper = ode.StepHandler(self.world,
ode.StepHandler.QuickStep,
time_step,
max_frame_time,
time_scale)
ent = sm.createEntity('crate','Barrel.mesh')
ent.setQueryFlags(1<<2)
self.node = sm.rootSceneNode.createChildSceneNode('crate')
self.node.attachObject(ent)
ent.setNormaliseNormals(True)
ent.setCastShadows(True)

self.body = ode.Body(self.world)
self.node.attachObject(self.body)

size = ogre.Vector3(10.0,10.0,10.0)
mass = ode.BoxMass(0.5,size)
mass.setDensity(5.0,size)
geom = ode.BoxGeometry(size,self.world,self.space)
self.node.setScale(size.x*0.1,size.y*0.1,size.z*0.1)
self.body.setMass(mass)
geom.setBody(self.body)
ent.setUserObject(geom)

self.body.setOrientation(ogre.Quaternion(ogre.Radian(5.0),
ogre.Vector3(0,0,0)))
self.body.setPosition((0,80,20))

self.plane = ode.InfinitePlaneGeometry(ogre.Plane((0,1,0),0),
self.world,
self.world.getDefaultSpace())

s = sm.createStaticGeometry('StaticFloor')
s.setRegionDimensions((160,100,160))
s.setOrigin((0,-100,0))
i = 0
for z in range(-80,80,20):
for x in range(-80,80,20):
name = 'Plane_'+str(i)
i+=1
ent = sm.createEntity(name,'plane.mesh')
ent.setQueryFlags(1<<4)
ent.setUserObject(self.plane)
s.addEntity(ent,ogre.Vector3(x,0,z))
#ent.scale = 0.05,0.05,0.05
s.build()


def _createCamera(self):
self.camera = self.sceneManager.createCamera('PlayerCam')
self.camera.position =0,10,-30
self.camera.lookAt((0,0,0))
self.camera.nearClipDistance = 1

def _createViewports (self):
viewport = self.renderWindow.addViewport(self.camera)
viewport.backGroundColor = (0,0,0)
self.camera.aspectRatio = float (viewport.actualWidth) / float (viewport.actualHeight)

def _createFrameListener(self):
self.frameListener = OdeListener(self.renderWindow,
self.camera,
self.world,
self.stepper)

self.frameListener.showDebugOverlay(True)
self.root.addFrameListener(self.frameListener)
if __name__ == '__main__':
ta = TutorialApplication ()
ta.go ()


At this moment the barrel( i didnt have a crate mesh) falls through the
floor.That was all for that tutorial.

Since i dont have much experience in ode i wanna know how to make my object fall less faster.Can someone please tell me how :?:

dermont

14-06-2008 00:48:16

Did you try changing the step time to "stepper.step(frameEvent.timeSinceLastFrame)" as suggested in the tutorial.

Also you are passing a sceneManager to a World i.e. ode.World(self.sceneManager) before the sceneManager has even been created, check sf_OIS.py, the howto's and tutorials http://wiki.python-ogre.org/index.php/Main_Page for the order in which things are created.

For specific OgreOde questions you may get a better response on the OgreODE forums. It's been some time since I've used OgreOde so there are probably bugs:


import ogre.renderer.OGRE as ogre
import SampleFramework as sf
import ogre.physics.OgreOde as ode
from math import *

class OdeListener(sf.FrameListener, ode.CollisionListener):
def __init__(self, renderWindow, camera,world,stepper):
sf.FrameListener.__init__(self, renderWindow, camera)
ode.CollisionListener.__init__(self)
self.world = world
self.stepper = stepper
self.world.setCollisionListener(self)

def frameStarted(self, frameEvent):
#time = 1.0/60.0
if self.stepper.step(frameEvent.timeSinceLastFrame):
self.world.synchronise()

return sf.FrameListener.frameStarted(self, frameEvent)


def collision( self, contact) :
## Check for collisions between things that are connected and ignore them
g1 = contact.getFirstGeometry()
g2 = contact.getSecondGeometry()

if (g1 and g2):
b1 = g1.getBody()
b2 = g2.getBody()
if (b1 and b2 and ode.Joint.areConnected(b1, b2)):
return False

## Set the friction at the contact
## Infinity didn't get exposed :(
contact.setCoulombFriction( 9999999999 ) ### OgreOde.Utility.Infinity)
contact.setBouncyness(0.1)

## Yes, this collision is valid
return True

class TutorialApplication (sf.Application):
def __init__(self):
sf.Application.__init__(self)
self.world = 0
self.plane = 0
self.geoms = []
self.bodies = []

def _createScene (self):

# create World
self.world = ode.World(self.sceneManager)
self.world.setGravity((0,-9.80665, 0))
self.world.setCFM(10e-5)
self.world.setERP(0.8)
self.world.setAutoSleep(True)
self.world.setAutoSleepAverageSamplesCount(10)
self.world.setContactCorrectionVelocity(1.0)
space = self.world.getDefaultSpace()
self.world.setShowDebugGeometries(True)

sm = self.sceneManager

sm.ambient = 1,1,1
time_step = 0.5
time_scale = 1.7
max_frame_time = 1.0/4
self.time_step = time_step
self.time_scale = 1.0
self.max_frame_time =1.0 / 4
self.frame_rate = 1.0 / 60

self.stepper = ode.StepHandler(self.world,
ode.StepHandler.QuickStep,
time_step,
max_frame_time,
time_scale)

##self.stepper.setAutomatic(ode.StepHandler.AutoMode_PreFrame, self.root)
##self.stepper.setAutomatic(ode.StepHandler.AutoMode_PostFrame, self.root)
### will automatically do in frameStarted or frameEnded the code
### if self.stepper.step(frameEvent.timeSinceLastFrame):
### self.world.synchronise()

self.plane = ode.InfinitePlaneGeometry(ogre.Plane((0,1,0),0),
self.world,
self.world.getDefaultSpace())

s = sm.createStaticGeometry('StaticFloor')
s.setRegionDimensions((160,100,160))
s.setOrigin((0,-100,0))
i = 0
for z in range(-80,80,20):
for x in range(-80,80,20):
name = 'Plane_'+str(i)
i+=1
ent = sm.createEntity(name,'plane.mesh')
ent.setQueryFlags(1<<4)
ent.setUserObject(self.plane)
s.addEntity(ent,ogre.Vector3(x,0,z))
#ent.scale = 0.05,0.05,0.05
s.build()


ent = sm.createEntity('crate','Barrel.mesh')
ent.setQueryFlags(1<<2)
node = sm.getRootSceneNode().createChildSceneNode('crate')
node.attachObject(ent)
ent.setNormaliseNormals(True)
ent.setCastShadows(True)

body = ode.Body(self.world)
self.bodies.append( body )

size = ogre.Vector3(5.31985, 6.11992, 5.31985)

mass = ode.BoxMass(0.5,size)
#mass.setDensity(0.01,size)
geom = ode.BoxGeometry(size,self.world,space)
self.geoms.append( geom )
body.setMass(mass)
node.attachObject(body)
geom.setBody(body)
#node.setScale(size)
ent.setUserObject(geom)

#w = ogre.Radian( ode.Utility.randomReal() * 10.0 - 5.0 )
#x = ode.Utility.randomReal() * 2.0 - 1.0
#y = ode.Utility.randomReal() * 2.0 - 1.0
#z = ode.Utility.randomReal() * 2.0 - 1.0
#body.setOrientation( ogre.Quaternion(w, ogre.Vector3(x,y,z) ) )

body.setPosition((0,80,20))
#node.showBoundingBox(True)


def _createCamera(self):
self.camera = self.sceneManager.createCamera('PlayerCam')
self.camera.position =0,10,-30
self.camera.lookAt((0,0,0))
self.camera.nearClipDistance = 1

def _createViewports (self):
viewport = self.renderWindow.addViewport(self.camera)
viewport.backGroundColor = (0,0,0)
self.camera.aspectRatio = float (viewport.actualWidth) / float (viewport.actualHeight)

def _createFrameListener(self):
self.frameListener = OdeListener(self.renderWindow,
self.camera,
self.world,
self.stepper)

self.frameListener.showDebugOverlay(True)
self.root.addFrameListener(self.frameListener)

def cleanUp (self):
## Stop listening for collisions
if (self.world.getCollisionListener() == self):
self.world.setCollisionListener(None)
del self.plane ## delete our plane

## Run through the list of bodies we're monitoring
clearList = []

while len(self.bodies):
body = self.bodies.pop()
## get the scene node this body controls
node = body.getParentSceneNode()
if (node):
name = node.getName()
clearList+=[ node.getAttachedObject(j)
for j in range(node.numAttachedObjects())
if node.getAttachedObject(j).getMovableType() != body.getMovableType() ]
## Destroy the node by name
self.sceneManager.getRootSceneNode().removeAndDestroyChild(name)
## Delete the body
del body

## Remove all the entities we found attached to scene nodes we're controlling
while len(clearList):
p = clearList.pop()
if (p.getMovableType() == "Entity") :
print "Movables for Deletion %s %s" % (p.getMovableType(),p.getName())
self.sceneManager.destroyMovableObject(p.getName(), 'Entity')
elif (p.getMovableType() == "ParticleSystem") :
self.sceneManager.destroyParticleSystem(p.getName())
del p

## Delete all the collision geometries
while len(self.geoms):
p = self.geoms.pop()
del p

assert (len(self.geoms) == 0 )
assert (len(self.bodies) == 0 )
assert (len(clearList) == 0 )

del self.stepper

if __name__ == '__main__':
ta = TutorialApplication ()
ta.go ()
ta.cleanUp()

nicolasbrown

16-06-2008 12:49:31

thx alot.You said that you havent used ogreode in a while now.Then what do you use?

bharling

18-06-2008 17:03:45

Hey, wow this thread has suddenly become full of really useful code.

well done and thanks to both of you ( much more help than I was ) :P

theTrav

02-04-2009 01:26:29

Anyone going to add these to the wiki?
I haven't tried them yet but they look to be quite useful for someone like myself (have done 3d graphics code before, have done py-ode stuff before, have not used ogre before)

I'm willing to have a bash at it, but it'd probably be better for someone who actually knows what's going on to do it, basically you just need to copy the code, cut it into sections, and have a ramble after every few lines to discuss what those lines were doing.