I've got a little problem with newton, substeps aren't working, try this code with sync rate to 100, then with sync rate to 10, everything is going slow. So, is that me or a bug ?
sync on
sync rate 100
ndb_newtoncreate
NDB_SetVector 0.0, -98.1, 0.0
NDB_SetStandardGravity
NDB_SetVector 1, -2000, -200, -2000
NDB_SetVector 2, 2000, 2000, 2000
NDB_NewtonSetWorldSize
NDB_NewtonSetMinimumFrameRate 100
make object box 1,100,10,100 : position object 1,0,-100,0
make object box 2,100,10,100 : position object 2,0,100,0
make object cube 3,20
position object 3,0,120,0
make_box(3,20)
position camera 0,0,-300
rotate camera 0,0,0
ntime# = NDB_GetElapsedTimeInSec()
ntime# = NDB_GetElapsedTimeInSec()
do
rem update
ntime# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate ntime#
rem position
body=NDB_getbody(3)
NDB_BodyGetPosition body
py#=NDB_GetVector_y()
rem timer
if py#<=100
if first=0
first=1
starttime=timer()
color object 2,rgb(255,0,0)
endif
if py#<=-100
if last=0
last=1
endtime=timer()
color object 1,rgb(255,0,0)
endif
text 0,0,str$(endtime-starttime)+" ms"
else
text 0,0,str$(timer()-starttime)
endif
endif
sync
loop
function make_box(newtonobj,mass#)
x#=object position x(newtonobj)
y#=object position y(newtonobj)
z#=object position z(newtonobj)
ax#=object angle x(newtonobj)
ay#=object angle y(newtonobj)
az#=object angle z(newtonobj)
sizex#=object size x(newtonobj,1):sizey#=object size y(newtonobj,1):sizez#=object size z(newtonobj,1)
rem on crée les données des collisions
index = NDB_NewtonCreateBox(sizex#, sizey#, sizez#)
rem on crée un corp
Body = NDB_NewtonCreateBody(index)
rem calculs liés a la masse (moment d'inertie)
if mass#>0
NDB_BodySetGravity Body, 1
NDB_CalculateMIBoxSolid mass#, sizex#,sizey#,sizez#
NDB_NewtonBodySetMassMatrix Body, mass#
endif
rem
NDB_NewtonReleaseCollision index
rem positions/angles du solide
NDB_BuildMatrix ax#, ay#, az#, x#, y#, z#
NDB_NewtonBodySetMatrix body
rem objet visible
NDB_BodySetDBProData body,newtonobj
NDB_NewtonBodySetDestructorCallback Body
endfunction body