Check out this little demo. I've implemented a whole load of your stuff, and made some functions to make it quicker to set up objects and features such as bridges and ropes.
You can have a look at the cart I've made. See if you can find a way to make the back wheels provide a driving force (ie. rotate in the right direction).
Copy it to the same folder as all the other demos.
Arrowkeys move the ball.
` demo
` setup
sync on
sync rate 0
autocam off
` intialize newton
NDB_NewtonCreate
` floor
make_Newton_box(1,300,10,300,0)
load image "FLOOR1.BMP",1:texture object 1,1
scale object texture 1,2,2
make_Newton_box(2,300,10,300,0):position_Newton_object(2,650,100,0)
texture object 2,1: scale object texture 2,2,2
` make ball
make_Newton_ball(10,15,10)
position_Newton_object(10,0,45,0)
load image "balltex.bmp",2:texture object 10,2
` rope
r=40
for x=-100 to 100 step 50
for z=-100 to 100 step 50
x#=x:z#=z
rope(r,x#,200,z#,5,180,4,0)
inc r,4
next z
next x
` bridge
position camera 0,200,-300
point camera 0,object position y(10),0
bridge(11,150,0,0,500,100,0,50,5,25,20)
` block
block(500,575,100,0,50,100,100,3,3,3)
` cart
cart(300,-75,75,75)
` setup materials
FloorMat = NDB_NewtonMaterialCreateGroupID()
BallMat = NDB_NewtonMaterialCreateGroupID()
NDB_NewtonMaterialSetDefaultFriction FloorMat,BallMat,100,100
NDB_NewtonMaterialSetDefaultElasticity FloorMat,BallMat, 0.1
NDB_NewtonMaterialSetDefaultSoftness FloorMat,BallMat,0.5
` apply materials
NDB_NewtonBodySetMaterialGroupID 1,FloorMat
NDB_NewtonBodySetMaterialGroupID 2,FloorMat
NDB_NewtonBodySetMaterialGroupID 10,BallMat
for o=11 to 20:NDB_NewtonBodySetMaterialGroupID o,FloorMat:next o
for o=300 to 304:NDB_NewtonBodySetMaterialGroupID o,ballMat:next o
do
NDB_NewtonUpdate
t=10
position camera object position x(t),object position y(t)+200,object position z(t)-300
point camera object position x(t),object position y(t),object position z(t)
move=0:vx#=0:vy#=0:vz#=0
` move
if upkey()=1 then vx#=50:move=1
if downkey()=1 then vx#=-50:move=1
if rightkey()=1 then vz#=-50:move=1
if leftkey()=1 then vz#=50:move=1
if move=1 then NDB_SetVector vx#,vy#,vz#: NDB_NewtonBodySetOmega 10
` restart
if object position y(t)<-200 then position_Newton_object(10,0,45,0)
sync
loop
` FUNCTIONS ***********************************************************************
` make newton box
function make_Newton_box(obj,sx#,sy#,sz#,m#)
` col identity
col1 = NDB_NewtonCreateBox(sx#,sy#,sz#,0)
` make object
make object box obj,sx#,sy#,sz#
` set collision
NDB_NewtonCreateBody obj, col1
` colision data
NDB_NewtonBodySetDestructorCallback obj
NDB_NewtonBodySetTransformCallback obj
NDB_NewtonBodySetForceAndTorqueCallback obj
NDB_NewtonBodySetMassMatrix obj,m#, 1.0, 1.0, 1.0
NDB_NewtonBodySetAutoFreeze obj, 0
endfunction
` make newton ball
function make_Newton_ball(obj,r#,m#)
` col identity
col1 = NDB_NewtonCreateSphere(r#, 0)
` make object
make object sphere obj,2*r#
` set collision
NDB_NewtonCreateBody obj, col1
` colision data
NDB_NewtonBodySetDestructorCallback obj
NDB_NewtonBodySetTransformCallback obj
NDB_NewtonBodySetForceAndTorqueCallback obj
NDB_NewtonBodySetMassMatrix obj,m#, 1.0, 1.0, 1.0
NDB_NewtonBodySetAutoFreeze obj, 0
endfunction
` position newton object
function position_Newton_object(obj,x#,y#,z#)
NDB_SetVector object angle x(obj),object angle y(obj),object angle z(obj)
NDB_SetVectorToRadians
NDB_NewtonSetEulerAngle
NDB_SetMatrixIdentityMatrix
NDB_SetVector x#,y#,z#, 1.0
NDB_SetMatrixPosRow
NDB_NewtonBodySetMatrix obj
position object obj, NDB_GetVector_X(), NDB_GetVector_Y(), NDB_GetVector_Z()
endfunction
` rotate newton object
function rotate_Newton_object(obj,ax#,ay#,az#)
NDB_SetVector ax#,ay#,az#
rotate object obj, NDB_GetVector_X(), NDB_GetVector_Y(), NDB_GetVector_Z()
NDB_SetVectorToRadians
NDB_NewtonSetEulerAngle
NDB_SetVector object position x(obj),object position y(obj),object position z(obj)
NDB_SetMatrixPosRow
NDB_NewtonBodySetMatrix obj
position object obj, NDB_GetVector_X(), NDB_GetVector_Y(), NDB_GetVector_Z()
endfunction
` rope function
function rope(obj,x#,y#,z#,w#,h#,links,ledge)
sy#=h#/links
` make top
make_Newton_box(obj,w#,sy#,w#,0.5)
position_newton_object(obj,x#,(y#-sy#/2),z#)
` ball and socket joint
NDB_SetVector x#,y#,z#
Joint = NDB_NewtonConstraintCreateBall(obj,ledge)
NDB_SetVector 0.0, 1.0, 0.0
NDB_NewtonBallSetConeLimits Joint,0,0
` rest
for a=1 to links-1
` make top
make_Newton_box(obj+a,w#,sy#,w#,1)
position_newton_object(obj+a,x#,(y#-sy#/2)-(sy#*a),z#)
` ball and socket joint
NDB_SetVector x#,y#-(sy#*a),z#
Joint = NDB_NewtonConstraintCreateBall((obj+a),(obj+a-1))
NDB_SetVector 0.0, -1.0, 0.0
NDB_NewtonBallSetConeLimits Joint,0,0
next a
endfunction
` bridge function
function bridge(obj,x#,y#,z#,x1#,y1#,z1#,w#,h#,slack#,links)
d#=sqrt((x#-x1#)^2+(z#-z1#)^2)+slack#
a#=atanfull((x#-x1#),(z#-z1#))
sy#=(d#/links)
` make links
ox#=x#:oy#=y#:oz#=z#
make object cube obj+links,10
for a=0 to links-1
` make piece
make_Newton_box(obj+a,w#,h#,sy#,1)
dist#=sy#
if a=0 then dist#=dist#/2
position object obj+links,ox#,oy#,oz#
dx#=x1#-x#:dy#=y1#-y#:dz#=z1#-z#
point object obj+links,ox#+dx#,oy#+dy#,oz#+dz#:move object obj+links,dist#
px#=object position x(obj+links):py#=object position y(obj+links):pz#=object position z(obj+links)
position_Newton_object(obj+a,px#,py#,pz#)
set object to object orientation obj+a,obj+links
rotate_Newton_object(obj+a,object angle x(obj+links),object angle y(obj+links),object angle z(obj+links))
` link to previous
obj1=(obj+a-1)
if a=0 then obj1=0
NDB_SetVector 1,(ox#+px#)/2,(oy#+py#)/2,(oz#+pz#)/2
NDB_SetVector 2,newxvalue(0,a#+90,1),0,newzvalue(0,a#+90,1)
Hinge = NDB_NewtonConstraintCreateHinge(obj+a,obj1)
` end
ox#=px#:oy#=py#:oz#=pz#
e=a
next a
` end of bridge
position object obj+links,x1#,y1#,z1#
point object obj+links,x#,y#,z#:move object obj+links,0-sy#/2
px#=object position x(obj+links):py#=object position y(obj+links):pz#=object position z(obj+links)
` position/rotate
position_Newton_object(obj+e,px#,py#,pz#)
set object to object orientation obj+e,obj+links
rotate_Newton_object(obj+e,object angle x(obj+links),object angle y(obj+links),object angle z(obj+links))
` link to point
NDB_SetVector 1,x1#,y1#,z1#
NDB_SetVector 2,newxvalue(0,a#+270,1),0,newzvalue(0,a#+270,1)
Hinge = NDB_NewtonConstraintCreateHinge(obj+e,0)
rotate_Newton_object(obj+e,0,object angle y(obj+e),0)
delete object obj+links
endfunction
` newton block
function block(obj,x#,y#,z#,sx#,sy#,sz#,divx,divy,divz)
w#=sx#/divx:h#=sy#/divy:d#=sz#/divz
r=obj
x1=(x#-sx#/2):x2=(x#+sx#/2)-w#
y1=y#:y2=y#+sy#-h#
z1=(z#-sz#/2):z2=(z#+sz#/2)-d#
w=w#:h=h#:d=d#
for px=x1 to x2 step w
for py=y1 to y2 step h
for pz=z1 to z2 step d
make_Newton_box(r,w#,h#,d#,1)
px#=px+w#/2:py#=py+h#/2:pz#=pz+d#/2
position_Newton_object(r,px#,py#,pz#)
r=r+1
next pz
next py
next px
endfunction
` cart
function cart(obj,x#,y#,z#)
make_Newton_box(obj,20,20,30,10)
position_Newton_object(obj,x#,y#,z#)
for w=1 to 4
make_Newton_ball(obj+w,6,2)
texture object obj+w,2
scale object obj+w,40,100,100
next w
position_Newton_object(obj+1,x#-10,y#-8,z#+12)
position_Newton_object(obj+2,x#+10,y#-8,z#+12)
position_Newton_object(obj+3,x#-10,y#-8,z#-12)
position_Newton_object(obj+4,x#+10,y#-8,z#-12)
l1=2:l2=0
` ball and socket joint
NDB_SetVector x#-10,y#-8,z#+12
Joint = NDB_NewtonConstraintCreateBall((obj+1),obj)
NDB_SetVector +0, 0.0, 0.0
NDB_NewtonBallSetConeLimits Joint,l1,l2
` ball and socket joint
NDB_SetVector x#+10,y#-8,z#+12
Joint = NDB_NewtonConstraintCreateBall((obj+2),obj)
NDB_SetVector -0, 0.0, 0.0
NDB_NewtonBallSetConeLimits Joint,l1,l2
` ball and socket joint
NDB_SetVector x#-10,y#-8,z#-12
Joint = NDB_NewtonConstraintCreateBall((obj+3),obj)
NDB_SetVector +0, 0.0, 0.0
NDB_NewtonBallSetConeLimits Joint,l1,l2
` ball and socket joint
NDB_SetVector x#+10,y#-8,z#-12
Joint = NDB_NewtonConstraintCreateBall((obj+4),obj)
NDB_SetVector -0, 0.0, 0.0
NDB_NewtonBallSetConeLimits Joint,l1,l2
endfunction
coincidence? how about pure cosmic convergence!