Petr Schreiber
09-08-2007, 20:41
Hi,
here is translation of Python ODE01.PY script to our precious ( thinBASIC :) )
thinBASIC source adds saving to file as bonus :)
uses "FILE"
#include "thinbasic_ode.inc"
' -- Yes, to create new world is that easy
dim myWorld as dWorldID = dWorldCreate
' -- Creates generall body
dim myBody as dBodyID = dBodyCreate( myWorld )
' -- Here we will store mass
dim myMass AS dMass
' -- Planet Earth
dWorldSetGravity(myWorld, 0, -9.81, 0)
' -- Although it might seem like something else, we give DENSITY and RADIUS
dMassSetSphere( myMass, 2500.0, 0.05 )
' -- Here the actual mass
myMass.mass = 1
' -- Assign mass to body
dBodySetMass( myBody, myMass )
' -- Lets position mass at x, y, z
dBodySetPosition( myBody, 0, 2, 0 )
' -- May the Force be with our body
dBodyAddForce( myBody, 0, 200, 0 )
dim total_time as double
' -- Delta of time - 0.04 => like 25 FPS
dim dt as double = 0.04
' -- Variables to store position and speed
dim x, y, z, u, v, w AS dReal
dim fileOutput as string
while ( total_time < 2.0 )
ParseVector(dBodyGetPosition ( myBody ), x, y, z)
ParseVector(dBodyGetLinearVel ( myBody ), u, v, w)
fileoutput += 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
dWorldStep( myworld, dt) ' -- Increases step in simulation
total_time +=dt
WEND
FILE_SAVE( APP_SOURCEPATH+"ODE_Output.txt", fileoutput )
' -- All created must be destroyed
dBodyDestroy( myBody )
dWorldDestroy( myWorld )
msgbox 0, "Script finished, results saved to ODE_Output.txt"
sub ParseVector( byval pointer as dword, byref b as SINGLE, byref c as single, byref d as single )
b = peek(single, pointer)
c = peek(single, pointer+4)
d = peek(single, pointer+8)
end sub
I will try to translate even the 2 more examples, although I am not sure if they need callbacks yet.
Bye,
Petr
here is translation of Python ODE01.PY script to our precious ( thinBASIC :) )
thinBASIC source adds saving to file as bonus :)
uses "FILE"
#include "thinbasic_ode.inc"
' -- Yes, to create new world is that easy
dim myWorld as dWorldID = dWorldCreate
' -- Creates generall body
dim myBody as dBodyID = dBodyCreate( myWorld )
' -- Here we will store mass
dim myMass AS dMass
' -- Planet Earth
dWorldSetGravity(myWorld, 0, -9.81, 0)
' -- Although it might seem like something else, we give DENSITY and RADIUS
dMassSetSphere( myMass, 2500.0, 0.05 )
' -- Here the actual mass
myMass.mass = 1
' -- Assign mass to body
dBodySetMass( myBody, myMass )
' -- Lets position mass at x, y, z
dBodySetPosition( myBody, 0, 2, 0 )
' -- May the Force be with our body
dBodyAddForce( myBody, 0, 200, 0 )
dim total_time as double
' -- Delta of time - 0.04 => like 25 FPS
dim dt as double = 0.04
' -- Variables to store position and speed
dim x, y, z, u, v, w AS dReal
dim fileOutput as string
while ( total_time < 2.0 )
ParseVector(dBodyGetPosition ( myBody ), x, y, z)
ParseVector(dBodyGetLinearVel ( myBody ), u, v, w)
fileoutput += 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
dWorldStep( myworld, dt) ' -- Increases step in simulation
total_time +=dt
WEND
FILE_SAVE( APP_SOURCEPATH+"ODE_Output.txt", fileoutput )
' -- All created must be destroyed
dBodyDestroy( myBody )
dWorldDestroy( myWorld )
msgbox 0, "Script finished, results saved to ODE_Output.txt"
sub ParseVector( byval pointer as dword, byref b as SINGLE, byref c as single, byref d as single )
b = peek(single, pointer)
c = peek(single, pointer+4)
d = peek(single, pointer+8)
end sub
I will try to translate even the 2 more examples, although I am not sure if they need callbacks yet.
Bye,
Petr