Hello
First thanks Walaber & Kjelle for this wonderfull physic engine
Here is my modest contribution :
A function that does the DBPro's "point object" command but for Newtons object too -
`function to point Obj/nObj at Target direction
`Obj=DBPro object number
`nObj=Newton Body of Obj
`Target=DBPro object number to point at
function PointAt(Obj,nObj,Target)
Objx#=object position x(Obj)
Objz#=object position z(Obj)
`make a dummy, put it at Obj position and angle, move it a bit
Dummy=FreeObject()
make object box Dummy,1,1,1
position object Dummy,Objx#,0,Objz#
rotate object Dummy,object angle x(Obj),object angle y(Obj),object angle z(Obj)
move object Dummy,1
Dumx#=object position x(Dummy)
Dumz#=object position z(Dummy)
Tarx#=object position x(Target)
Tarz#=object position z(Target)
`make a vector from Obj to Target and grab its normal
a=5000
null=make vector3(a)
set vector3 a,Tarx#-Objx#,0,Tarz#-Objz#
normalize vector3 a,a
`make a vector from Obj to Dummy
b=5001
null=make vector3(b)
set vector3 b,Dumx#-Objx#,0,Dumz#-Objz#
normalize vector3 b,b
`Calculate angle between the 2 vectors
Angle1#=acos(dot product vector3(a,b))
`make cross product of the above 2 vectors
`the result is stored in a third vector
`the anble between vector a and this last vector
`will give the direction to turn :
`if it is equal or more than 90° then the shortest way is right
c=5002
null=make vector3(c)
set vector3 c,0,1,0
cross product vector3 c,b,c
Angle2#=acos(dot product vector3(a,c))
if angle1# > 0.1
if angle2# <> 0
Rem PJY - select whether to turn right or left
if angle2# >= 90
inc rotat#,3
else
dec rotat#,3
endif
endif
endif
`filling temp vector with the desired Force
NDB_SetVector 0.0,rotat#,0.0
`applying the desired force to rotate nObj
NDB_NewtonBodySetOmega nObj
delete object Dummy
endfunction
I used the Newton FPS demo and some
Kantaree's vectors tutorial to do it.
Perhaps there is a simplier way to achieve the same thing, if so feel free to teach me