The following example shows you the very basics of ODE: creating a world including a rigid body and doing a simulation loop. The example program does without any fancy graphics output, but just displays the bare numbers.
It is a translation of PyODE Tutorial 1, by Matthias Baas.
See: http://pyode.sourceforge.net/tutorials/tutorial1.html
' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "ODE.INC"
FUNCTION PBMAIN () AS LONG
LOCAL pWorld AS DWORD
LOCAL pBody AS DWORD
LOCAL tMass AS dMass
LOCAL total_time AS DOUBLE
LOCAL dt AS DOUBLE
LOCAL ps AS SINGLE PTR
LOCAL x, y, z AS SINGLE
LOCAL u, v, w AS SINGLE
LOCAL strOut AS STRING
' Create new world
pWorld = dWorldCreate
' Create general body
pBody = dBodyCreate(pWorld)
' Planet Earth
dWorldSetGravity(pWorld, 0, -9.81, 0)
' Give density and radius
dMassSetSphere(tMass, 2500.0, 0.05)
' Actual mass
tMass.mass = 1
' Assign mass to the body
dBodySetMass(pBody, tMass)
' Position mass at x, y, z
dBodySetPosition(pBody, 0, 2, 0)
' Add force
dBodyAddForce(pBody, 0, 200, 0)
' Do the simulation
dt = 0.04
WHILE total_time < 2.0!
ps = dBodyGetPosition(pBody)
IF ps THEN
x = @ps[0]
y = @ps[1]
z = @ps[2]
END IF
ps = dBodyGetLinearVel(pBody)
IF ps THEN
u = @ps[0]
v = @ps[1]
w = @ps[2]
END IF
strOut = strOut & FORMAT$(total_time, "0.00") & " sec: " & _
"pos = (" & FORMAT$(x, "0.000") & "," & FORMAT$(y, "0.000") & "," & FORMAT$(z, "0.000") & ")" & _
"vel = (" & FORMAT$(u, "0.000") & "," & FORMAT$(v, "0.000") & "," & FORMAT$(w, "0.000") & ")" & $CRLF
' Increase step in simulation
dWorldStep(pWorld, dt)
total_time = total_time + dt
WEND
' Cleanup
IF pBody THEN dBodyDestroy(pBody)
IF pWorld THEN dWorldDestroy(pWorld)
MSGBOX strOut
END FUNCTION
Thanks Jose, I should mention that Petr is writing some great ODE examples in thinBasic also. Just wanted others getting into ODE to know they can look at his code to get an idea too at the thinBasic forums.
http://community.thinbasic.com/index.php?board=103.0