I'm going to stick this in the newcomers board, since it's very probably a simple mistake, but one that's had me clueless for some time now, and it's embarrassing since I rarely need to ask for help... Here goes:
Right now I'm just messing about with 2 boxes, and trying all the types of joint on them, to see how the joints behave. I started out with ball/socket, and already I'm not quite getting something
I'm successfully managing to create the boxes, and apply gravity to them. but when I create the actual joint. me and newton are not agreeing...
ndb_setvector 1,5.0,1.0,0.5
ndb_setvector 2,1.0,0.0,0.0
Joint1 = ndb_newtonconstraintcreateball(Box2,Box1)
ndb_setvector 0.0,0.0,0.0
ndb_newtonballsetconelimits Joint1,30.0,60.0
ndb_buildmatrix 0.0,0.0,0.0,0.0,2.0,0.0
ndb_newtonbodysetmatrixrecursive Box1
I'm making two boxes each with dimensions of 5x2x1. then positioning the first box at 0,0,0 and colouring it red. I then position the second box at 5,0,0 and colour it blue. then using the snippet above, I make the joint. But it's not being created as I'm expecting it to be... I made a few milkshape mock-ups to help try and explain better...
Here is where I'm intending the boxes and the joint to appear
and a wireframe view so the joint (blue circle) is properly visible
The position I want the joint at is in the middle-point between the two boxes, which to me is 5.0,1.0,0.5
But that's not what seems to be happening...
instead it seems to be placing the joint here
and a wireframe view
Can anyone see why I've got this wrong? Without the SetMatrixRecursive command, the boxes at least appear in the right place (but the joint is still in the wrong place). I assume it is setting temp vector 2 that is throwing it since I want the pin to point straight to the right, which in my opinion is 0,90,0, but the included tutorial "demo 3" says down is 0,-1,0
Here's the entire source in case the error is somewhere else.
The 2 external x files can be generated internally with make object box, or a modelling program could be used:
world.x is 50x10x50 units
box.x is 5x2x1 units
set display mode 1024,768,16
sync rate 30 : sync on : sync
position camera 0,3,-5
autocam off
ndb_newtoncreate
ndb_newtonsetsolvermodel 0
ndb_newtonsetfrictionmodel 1
time = ndb_getelapsedtimeinsec()
time = ndb_getelapsedtimeinsec()
ndb_setvector 0.0,-9.8,0.0
ndb_setstandardgravity
WorldCol = ndb_newtoncreatebox(50.0,10.0,50.0)
World = ndb_newtoncreatebody(WorldCol)
ndb_buildmatrix 0.0,0.0,0.0,0.0,-10.0,0.0
ndb_newtonbodysetmatrix World
ndb_newtonreleasecollision World
load object "world.x",1
position object 1,10,-10,0
color object 1,rgb(255,0,0)
ndb_newtonbodysetdestructorcallback World
ndb_bodysetdbprodata World,1
BoxCol1 = ndb_newtoncreatebox(5.0,2.0,1.0)
Box1 = ndb_newtoncreatebody(BoxCol1)
ndb_buildmatrix 0.0,0.0,0.0,0.0,0.0,0.0
ndb_newtonbodysetmatrix Box1
ndb_calculatemiboxsolid 0.0,5.0,2.0,1.0
ndb_newtonbodysetmassmatrix Box1,0.0
ndb_newtonreleasecollision BoxCol1
load object "box.x",2
position object 2,5,2,1
color object 2,rgb(255,31,0)
ndb_newtonbodysetdestructorcallback Box1
ndb_bodysetdbprodata Box1,2
ndb_bodysetgravity Box1,0
BoxCol2 = ndb_newtoncreatebox(5.0,2.0,1.0)
Box2 = ndb_newtoncreatebody(BoxCol2)
ndb_buildmatrix 0.0,0.0,0.0,5.0,0.0,0.0
ndb_newtonbodysetmatrix Box2
ndb_calculatemiboxsolid 15.0,5.0,2.0,1.0
ndb_newtonbodysetmassmatrix Box2,15.0
ndb_newtonreleasecollision BoxCol2
load object "box.x",3
position object 3,10,2,1
color object 3,rgb(0,95,255)
ndb_newtonbodysetdestructorcallback Box2
ndb_bodysetdbprodata Box2,3
ndb_bodysetgravity Box2,1
//Up to here works fine!
//or put it another way -- works as I'm expecting it to.
ndb_setvector 1,5.0,1.0,0.5
ndb_setvector 2,0.0,1.0,0.0
Joint1 = ndb_newtonconstraintcreateball(Box2,Box1)
ndb_setvector 0.0,0.0,0.0
ndb_newtonballsetconelimits Joint1,30.0,60.0
ndb_buildmatrix 0.0,0.0,0.0,0.0,2.0,0.0
ndb_newtonbodysetmatrixrecursive Box1
//Somewhere in the above code is where the diagrams help describe what I'm trying to achieve, and what's actually being achieved
global oldtime as dword
global time as dword
oldtime = timer()
do
time = timer()
if time >= oldtime + 0.10
ChildXRotate as double float
ChileNXRotate as double float
ndb_newtonupdate 0.01
ChildXRotate = mousemovex()
if ChildXRotate <> 0
ndb_setvector 1,0.0,0.0,0.0
ndb_setvector 2,ChildXRotate,0.0,0.0
ndb_bodyaddforcelocal Box2
endif
ChildNXRotate = mousemovey()
if ChildNXRotate <> 0
if shiftkey() = 1
ndb_setvector 1,0.0,0.0,0.0
ndb_setvector 2,0.0,0.0,ChildNXRorate
ndb_bodyaddforcelocal Box2
else
ndb_setvector 1,0.0,0.0,0.0
ndb_setvector 2,0.0,ChildNXRotate,0.0
ndb_bodyaddforcelocal Box2
endif
endif
if upkey() = 1
move camera 0.1
endif
if downkey() = 1
move camera -0.1
endif
if leftkey() = 1
yrotate camera wrapvalue(camera angle y() - 90)
move camera 0.1
yrotate camera wrapvalue(camera angle y() + 90)
endif
if rightkey() = 1
yrotate camera wrapvalue(camera angle y() + 90)
move camera 0.1
yrotate camera wrapvalue(camera angle y() - 90)
endif
oldtime = time
endif
fastsync
loop
function NeverCalled()
//Don't think I'll need this, but you can't be too careful
if memblock exist(1) then delete memblock 1
endfunction
I'd appreciate any help, since I think I'm almost all the way there...