I've been playing with newton recently and I've found a couple of things that I can't find answers to. Remember my philosophy, the only stupid questions are the ones you already know the answer for! Anyway:
For these commands:
NDB_NewtonSetSolverModel
NDB_NewtonSetFrictionModel
In the help files that come with the wrapper it says the settings are O, L and N, for the solver and O and L for the friction, unless I'm reading it wrong. But since the parameter should be an integer I don't see how I'm supposed to change the settings. Can anyone offer some help? Also, what're the default settings for these?
I've found what seems to be a potentially nasty problem with the physics. The following code was the start of a game, so there's some stuff in there I haven't removed:
hide mouse
sync on
sync rate 0
autocam off
set normalization on
backdrop on
rem setup clock control variables
global clock as dword
global tim as dword
global timago as dword
global timin as dword
global timins as dword
global timin#
global timins#
global speed#
global spud#
speed# = 1
spud# = 0.1
rem initialise newton simulation
ndb_newtoncreate
rem set the minimum frame rate of the simulation
ndb_newtonsetminimumframerate 50
rem set the world size
setupworld(-1000,-1000,-1000,1000,1000,1000)
ndb_newtonsetbodyleaveworldevent 0
ndb_setvector 1,0,-9.81 * 5,0
ndb_setstandardgravity
make object box 1,1500,4,1500
color object 1,RGB(25,250,10)
set object ambience 1, 80
col = NDB_NewtonCreateTreeCollision(1)
Room = NDB_NewtonCreateBody(col)
NDB_BodySetDBProData Room, 1
NDB_NewtonBodySetDestructorCallback Room
NDB_NewtonReleaseCollision col
NDB_BuildMatrix 0,0,0,0,-2,0
position object 1,0,-2,0
NDB_NewtonBodySetMatrix 1
rem draw the image
ink 0,0
box 0,0,8,8
box 8,8,16,16
ink rgb(255,255,255),0
box 8,0,16,8
box 0,8,8,16
get image 1,0,0,16,16,0
texture object 1,1
scale object texture 1,8,8
mass# = 10
size# = 2
rem create a ball
make object cube 800,size#
color object 800,RGB(rnd(255),rnd(255),rnd(255))
col = NDB_NewtonCreateBox(size#,size#,size#)
ballob = NDB_NewtonCreateBody(col)
NDB_BodysetDBProData ballob,800
NDB_CalculateMIBoxSolid (mass#*100),size#,size#,size#
NDB_NewtonBodySetMassMatrix ballob,(mass#*100)
NDB_BuildMatrix 0.0, 0.0, 0.0, 40.0, 5.0, 0.0
NDB_NewtonBodySetMatrix ballob
NDB_NewtonReleaseCollision col
NDB_BodySetGravity ballob,1
NDB_NewtonBodySetAutoFreeze ballob,0
rem preloop timer setup
timago = timer() - 1
rem begin main loop
do
rem grab timer
tim = timer()
timins = tim - timago
timago = tim
rem grab the real time step
timins# = timins
timins# = timins# * 0.001
if timin => 50
rem cap time step
timin = 50
timin# = 0.02
else
rem work out the time step
timin# = timin
timin# = timin# * 0.001
endif
timin# = timin# * speed#
rem control game time
if paused = 0
rem update clock
inc clock,timin
else
rem do things that are only done while the game is paused
endif
rem update newton physics using speed controller time step
ndb_newtonupdate timin#
rem do things that can only be done after newton has updated
inc ang#,mousemovex()
inc ing#,mousemovey()
if ing# => 45 then ing# = 45
if ing# <= -45 then ing# = -45
position camera 0.5-(sin(ang#)*50),20,0.5-(cos(ang#)*50)
rotate camera ing#,ang#,0
rem onscreen debug data
set cursor 0,0
print screen fps()
print scancode()
print timins
print timin#
print clock
print speed#
rem temporary speed controller
if spacekey()
speed# = spud#
else
speed# = 1
endif
pre = fire
fire = mouseclick()
if (fire = 1) and (pre = 0)
NDB_BuildMatrix camera angle x(),camera angle y(),camera angle z(),camera position x(),camera position y(),camera position z()
NDB_NewtonBodySetMatrix ballob
NDB_SetVector 1,((sin(ang#)*100)*cos(ing#)),(0-(sin(ing#)*100)),((cos(ang#)*100)*cos(ing#))
NDB_NewtonBodySetVelocity ballob
endif
rem refresh the screen
fastsync
rem end of main loop
loop
REM USER FUNCTIONS
rem memblock check
function DOH()
null = memblock exist(1)
null = mesh exist(1)
endfunction
rem setup newton world size
function setupworld(xm#,ym#,zm#,xl#,yl#,zl#)
rem setup the two vectors
ndb_setvector 1,xm,ym#,zm#
ndb_setvector 2,xl#,yl#,zl#
rem set the world
ndb_newtonsetworldsize
endfunction
Ok, this code sets up a simple scene with no need to external media, there's a block for a floor and a simple box. Move the camera around with the mouse and fire the block from the camera with the left mouse button. By holding the space bar the program will change the time step being given to Newton to slow time down in a sort of bullet time effect.
The potential problem is that the block seems to travel a different distance depending on what speed the time is running. It travels further at normal time then it does at 0.1. It seems to me that the movement damping has a greater effect the more times per second newton updates. I realise that floating point variables are notorious for having accuracy problems, but the difference I'm getting between the two speeds is huge, at normal time speed the block travels quite a distance and bounces a few times, while at 0.1 speed it hits the floor near the middle point and stops pretty much dead in it's tracks.
Could some other people try out the above code and see if you're getting the same problem I'm getting, and does anyone have any idea what's going on?
Thanks.
Don't look at me like that!
You're just jealous because the voices are talking to me!