Hi,
I have been working on my own physics functions recently, it's like a plugin instead it's been made in DBPro code.
There are almost 60 functions, I wont bother explaining them, because soon I will make some help files.
Basically, it's not like any common physics wrappers, and certainly no competitor to ODE and Newton, but it's good for just momentum physics, which means you can make really convincing physics in your racing game in just a few lines, or make them very complex.
Please note that this does not work with weight transfer yet, so there will be no flipping over of the car or anything.
All the functions will be put into a dba file which you can include.
How to install:
Download the plugin (attached). Put the ZPhysics.dba file in your project folder. Put the ZPhysics.ini keywods file in Editor>Keywords. (Not necesarry)
And that's pretty much it.
A little demo that caused me to win the DBPro coding challenges using my plugin:
DBPro, No media.
`Standard setup
Sync on : Sync rate 60
Set display mode 1024,768,16 : Hide mouse
Autocam off : Set camera range 1,0x7fffffff
`Load Physics Functions
#include "ZPhysics.dba"
`Start World Physics
Start_World_Physics()
Set_World_Standards()
`Create Player
create Bitmap 1,128,128 : set current bitmap 1
for x=1 to 64 : for y=1 to 64
if rnd(1)=1 then ink rgb(133,162,119),0 else ink rgb(0,128,0),0
box ((x*2)-2),((y*2)-2),(x*2),(y*2)
next x : next y
blur bitmap 1,3 : get image 5,1,1,128,128
set current bitmap 0 : delete bitmap 1
wheels=4
for w=1 to wheels
create_tyre(w,10,30,20.0,0.97,0.98,10.0)
next w
Create_Chassi(5,50,30,80,20.0,0.97,0.98,10.0)
texture object 5,5 : scale object texture 5,0.1,0.1
turn#=25.0
fuel#=200.0
`Create world
create bitmap 1,128,128 : set current bitmap 1
cls rgb(0,128,0)
for d=1 To 10000
ink rgb(0,rnd(255),rnd(50)),0
dot rnd(128),rnd(128)
next d
blur bitmap 1,4
get image 10,0,0,128,128
set current bitmap 0 : delete bitmap 1
`Create and Mold
make matrix 1,20000,20000,50,50
randomize matrix 1,50
prepare matrix texture 1,10,1,1
update matrix 1
`**Main loop**
Do
`Controls
if upkey()=1 or keystate(17)=1 then set_linear_force(5,dirX(5)*MoveConstant(5),dirY(5),DirZ(5)*MoveConstant(5))
if leftkey()=1
set_angular_force(1,0,-(Movespeed(1)/turn#),0)
set_angular_force(2,0,-(Movespeed(1)/turn#),0)
endif
if rightkey()=1
set_angular_force(1,0,(Movespeed(1)/turn#),0)
set_angular_force(2,0,(Movespeed(1)/turn#),0)
endif
if upkey()=0 and keystate(17)=0 or fuel#=0.0 then set_linear_force(5,0,0,0)
if leftkey()=0 and rightkey()=0 then set_angular_force(1,0,0,0) : set_angular_force(2,0,0,0)
Set_Next_Angle_Y(5,1,10.0)
For w=3 to 4
Set_Next_Angle_Y(w,5,10.0)
Next w
`Update Physics
for w=1 to wheels
Set_Linear_Velocity(w,VelX(5),VelY(5),VelZ(5))
Position_At_Object(w,5)
Place_On_Matrix(w,1,Object Size Y(w)/2)
next w
Place_On_Matrix(5,1,(Object Size Y(5)/2)+(Object Size Y(5)/5))
Calculate_Offsets_AB(1,5,0,315,60) : Calculate_Offsets_AB(2,5,0,45,60)
Calculate_Offsets_AB(3,5,0,135,60) : Calculate_Offsets_AB(4,5,0,215,60)
for w=1 to 5
Get_Old_Position(w)
Get_Object_Direction(w)
Get_Traction_Force(w)
Get_Drag_Force(w)
Get_Force(w)
Get_Speed(w)
Get_Acceleration(w)
Set_Acceleration(w)
Set_Velocity(w)
Get_Angular_Acceleration(w)
Get_Angular_Velocity(w)
Update_Coordinates_Slide(w)
Update_Angles(w)
Get_Lateral_Forces(w)
Fully_Update_Object_Position(w)
Update_Object_Rotation(w)
Get_Movement_Angle(w)
next w
if upkey()=0 and keystate(17)=0
if abs(MoveAngY(1)-AngleY(1)) < abs((MoveAngY(1)+180)-AngleY(1))
angleY(1)=curveangle(MoveAngY(1),angleY(1),10.0)
angleY(2)=curveangle(MoveAngY(1),angleY(2),10.0)
else
angleY(1)=curveangle(MoveAngY(1)+180,angleY(1),10.0)
angleY(2)=curveangle(MoveAngY(1)+180,angleY(2),10.0)
endif
endif
`Camera
ca#=curveangle(angleY(5),ca#,20.0)
cx#=positionX(5)-sin(ca#)*600
cz#=positionZ(5)-cos(ca#)*600
cy#=positionY(5)+300
position camera cx#,cy#,cz#
point camera positionX(5),positionY(5),positionZ(5)
`Create DashBoard
dec fuel#,movespeed(5)/2000
if fuel#<=0.0 then fuel#=0.0
ink rgb(0,0,0),0 : box 0,648,1024,768
create_meter(movespeed(5),60,708,5,30,rgb(255,0,255),rgb(255,255,0),"0","90","180","270")
create_meter(fuel#,964,708,5,30,rgb(255,0,255),rgb(255,255,0),"0","90","180","270")
ink rgb(255,255,255),0
text 110,652,"Speed: "
text 914-text width("Fuel: "),652,"Fuel: "
`**End loop**
Sync
Loop
`**Functions**
Function create_meter(var#,speedox,speedoy,speedow,speedl,col1,col2,m1$,m2$,m3$,m4$)
ink col1,0
circle speedox,speedoy,speedl
line speedox,speedoy,speedox+sin(wrapvalue(int(360-var#)+180))*(speedow/2),speedoy+cos(wrapvalue(int(360-var#)+180))*(speedow/2)
line speedox,speedoy,speedox-sin(wrapvalue(int(360-var#)+180))*(speedow/2),speedoy-cos(wrapvalue(int(360-var#)+180))*(speedow/2)
line speedox+sin(wrapvalue(int(360-var#)+180))*(speedow/2),speedoy+cos(wrapvalue(int(360-var#)+180))*(speedow/2),speedox+sin(wrapvalue(int(360-var#)+270))*speedl,speedoy+cos(wrapvalue(int(360-var#)+270))*speedl
line speedox-sin(wrapvalue(int(360-var#)+180))*(speedow/2),speedoy-cos(wrapvalue(int(360-var#)+180))*(speedow/2),speedox+sin(wrapvalue(int(360-var#)+270))*speedl,speedoy+cos(wrapvalue(int(360-var#)+270))*speedl
ink col2,0
center text speedox-(speedl*1.5),speedoy,m1$ : center text speedox,speedoy-(speedl*1.5),m2$
center text speedox+(speedl*1.5),speedoy,m3$ : center text speedox,speedoy+(speedl*1.5),m4$
endfunction
Tell me if you have any problems with it and I shall try to sort them out
Good day to you all...