I dont know if this is how it's done, but I think it is.
I made a bunch of arrays, with alot of types: Object (has data for the object such as traction and mass etc.), Force (linear and rotational for all axis) and energy (kinetic etc).
I know I didn't have an array for everything, but I think it's a good start.
Basically you can change an array so you can do different things to each object, I.e. Say you wanted to turn left, you give it a negative rotational force,
rot_force(1).y=-3
rot_force is the name of the array
the number in the brackets is the object number
the last bit(.x , .y or .z) is the axis.
The weight and energy of the object is calculated by the program. I.e. the weight is calculated by adding the world gravity and the mass of the object (both of which you need to set)
I only made one type of energy, kinetic, I didn't bother with potential because you can't go over the ground.
It still doesn't work like it should, I.e. It doesn't change the speed of movement depending on the mass or weight, but as I said it's only the rough idea.
Oh yes, and during the main loop dont forget to call the "Update_Physics()" Function, otherwise it wont work, and you also need to put the Sub where the arrays are all set up.
Here's a small demo.
`Setup
Sync on : Sync rate 60
Set display mode 1024,768,16 : hide mouse
Autocam off : set camera range 1,0x7fffffff
`Setup physics
Gosub Setup_Physics
`Create Box for example
make object box 1,50,20,100
object(1).mass=100
object(1).traction=0.95
`Create world
make matrix 1,10000,10000,50,50
world(0).gravity=9.8
`**Main Loop**
Do
`Control object
if upkey()=1
lin_force(1).x=sin(object(1).ay)*50
lin_force(1).z=cos(object(1).ay)*50
endif
if downkey()=1
lin_force(1).x=sin(object(1).ay)*-50
lin_force(1).z=cos(object(1).ay)*-50
endif
if leftkey()=1
rot_force(1).y=-3
endif
if rightkey()=1
rot_force(1).y=3
endif
if upkey()=0 and downkey()=0
lin_force(1).x=0 : lin_force(1).z=0
endif
if rightkey()=0 and leftkey()=0
rot_force(1).y=0
endif
`Update physics
update_physics()
`Control Camera
ca#=curveangle(object(1).ay,ca#,20.0)
cx#=object(1).x-sin(ca#)*600
cz#=object(1).z-cos(ca#)*600
cy#=object(1).y+300.0
position camera cx#,cy#,cz#
point camera object(1).x,object(1).y,object(1).z
`Show info
ink rgb(0,255,0),0
text 10,10,"Object linear force x: "+str$(lin_force(1).x)+" Newtons"
text 10,30,"Object linear force y: "+str$(lin_force(1).y)+" Newtons"
text 10,50,"Object linear force z: "+str$(lin_force(1).z)+" Newtons"
text 10,80,"Object rotational force x: "+str$(rot_force(1).x)+" Newtons"
text 10,100,"Object rotational force y: "+str$(rot_force(1).y)+" Newtons"
text 10,120,"Object rotational force z: "+str$(rot_force(1).z)+" Newtons"
text 10,160,"Object speed: "+str$(object(1).speed)+" Units per Cyce"
text 10,180,"Object kinetic energy: "+str$(energy(1).kinetic)+" Joules"
`**End Loop**
Sync
Loop
`**Subroutines
Setup_Physics:
type world
gravity as float
endtype
type object
mass as float
weight as float
speed as float
traction as float
x as float
y as float
z as float
ax as float
ay as float
az as float
xspeed as float
yspeed as float
zspeed as float
endtype
type force
x as float
y as float
z as float
endtype
type energy
kinetic as float
endtype
dim world(o) as world
dim lin_force(65535) as force
dim rot_force(65535) as force
dim object(65535) as object
dim energy(65535) as energy
Return
`**Functions**
`Update
Function Update_Physics()
for o=1 to 65535
if object exist(o)=1
`Equations
object(o).weight=object(o).mass*world(0).gravity
object(o).xspeed=lin_force(o).x
object(o).yspeed=lin_force(o).y
object(o).zspeed=lin_force(o).z
object(o).xspeed=object(o).xspeed*object(o).traction
object(o).yspeed=object(o).yspeed*object(o).traction
object(o).zspeed=object(o).zspeed*object(o).traction
object(o).speed=sqrt(object(o).xspeed^2+object(o).yspeed^2+object(o).zspeed^2)
energy(o).kinetic=(object(o).mass/2)*(object(o).speed^2)
object(o).x=object(o).x+object(o).xspeed
object(o).y=object(o).y+object(o).yspeed
object(o).z=object(o).z+object(o).zspeed
object(o).ax=wrapvalue(object(o).ax+rot_force(o).x)
object(o).ay=wrapvalue(object(o).ay+rot_force(o).y)
object(o).az=wrapvalue(object(o).az+rot_force(o).z)
`Update
position object o,object(o).x,object(o).y,object(o).z
rotate object o,object(o).ax,object(o).ay,object(o).az
endif
next o
Endfunction