ODE Ruby
ODE - Open Dynamics Engine
“ODE is an open source, high performance library for simulating rigid body dynamics.”
says introduction on ODE web page
ODER - ODE Ruby
ODE Ruby is direct binding to ODE library.
It’s not Object Oriented like Ruby ODE.
It is designed to be as similar as possible to the original ODE API.
In fact ODER binding is generated directly from ODE headers using SWIG.
Thanks to this you can use original ODE API documentation as a documentation for ODER.
Moreover, when a new version of ODE appears, simply run rake in ODER directory. Your ODER binding will be regenerated with new ODE calls.
You may need to adjust line 42 of rakefile to point gcc to your ruby installation directory.
Usage notes
- For functions returning arrays, like dBodyGetPosition, ruby arrays are returned.
- For functions accepting void*, like dGeomSetData, you can pass any ruby object.
- Functions requiring callback addresses, like dSpaceCollide2, should be called with standard ruby block.
- Whenever you need to pass 0 ID to functions like dCreatePlane(ID,…), pass nil instead.
- bool returning functions, like dGeomIsSpace, return 0 or 1.
- Whenever return-by-argument (using pointer) is used, like in dCollide, pass existing (correctly filled) array as reference. E.g. like this:
contacts = []
dCollide(geom1,geom2,3,contacts)
Usage example
require 'ode'
include Ode
world = dWorldCreate()
dWorldSetGravity(world,0,-9.81,0)
ball = dBodyCreate(world)
mass = DMass.new
dMassSetSphere(mass,1,1)
dBodySetMass(ball,mass)
dBodySetPosition(ball,0,10,0)
1.upto(100) {
dWorldStep(world,0.01)
puts "Ball position: "+dBodyGetPosition(ball).inspect
}
result:
Ball position: [0.0, 9.99901866912842, 0.0]
Ball position: [0.0, 9.99705696105957, 0.0]
...
Ball position: [0.0, 5.14404773712158, 0.0]
Ball position: [0.0, 5.04594755172729, 0.0]
More examples can be found in source tarball.
