Hi,
I was just messing with the new ODE commands and came up with a vehicle movement code. I hope you enjoy it. Use the arrow keys to move the box around.
Rem Project: ODE Physics Test
Rem Created: 11/8/2005 11:46:03 PM
Rem ***** Main Source File *****
sync on: sync rate 40
`MY COMMANDS ******************
make object cube 100, 2 : hide object 100
` Create the ODE World
ode start
ode set world gravity 0,-5,0
ode set world step 0.05
ode set world erp (0.2)*2.5
ode set world cfm (10^-5)*2.5
` Create a static floor. Implement in Dark Basic Professional first,
` and then ask ODE to do the same...
make object box 1,200,10,200
color object 1, rgb(128,255,128)
ode create static box 1
` Create 4 dynamic objects
` Implement in Dark Basic Professional first
` and then ask ODE to do the same...
make object box 2,10,5,8
`make object sphere 3,12,16,16
`make object cone 4, 10 : xrotate object 4, 90
`make object box 5,8,0.1,10 : xrotate object 5, 90
position object 2, -5,20,0
`position object 3, 3,40,3
`position object 4, 0,60,-3
`position object 5, 0,80,5
ode create dynamic box 2
`ode create dynamic sphere 3
`ode create dynamic triangle mesh 4
`ode create dynamic box 5
` continued…
` Add friction to our objects
ode set contact fdir1 1, 20.0
ode set contact fdir1 2, 1
`ode set contact fdir1 3, 20.0
`ode set contact fdir1 4, 20.0
`ode set contact fdir1 5, 20.0
` Position the camera, and watch what happens...
position camera 0, 50, -40
point camera 0,20,0
while spacekey() = 0
setFakeVehicle(2, 100, 5)
physicsObjectVehicle(2,100)
text 0,0, str$(object angle x(2))
text 0,10, str$(object angle y(2))
text 0,20, str$(object angle z(2))
point camera object position x(2), object position y(2), object position z(2)
ode update
sync
endwhile
` Tidy up...
ode end
end
function physicsObjectVehicle(objNum,fakeVehNum)
vehicleNumPosX# = object position x(objNum)
vehicleNumPosY# = object position y(objNum)
vehicleNumPosZ# = object position z(objNum)
fakeVehicleNumPosX# = object position x(fakeVehNum)
fakeVehicleNumPosY# = object position y(fakeVehNum)
fakeVehicleNumPosZ# = object position z(fakeVehNum)
offsetX# = fakeVehicleNumPosX# - vehicleNumPosX#
offsetY# = fakeVehicleNumPosY# - vehicleNumPosY#
offsetZ# = fakeVehicleNumPosZ# - vehicleNumPosZ#
if upkey()= 1 OR downkey() = 1 THEN ODE SET LINEAR VELOCITY objNum, offsetX#, offsetY#, offsetZ#
if rightkey() = 1 THEN ODE SET ANGULAR VELOCITY 2, 0, 2, 0
if leftkey() = 1 THEN ODE SET ANGULAR VELOCITY 2, 0, -2, 0
endfunction
function setFakeVehicle(objNum, fakeVehNum, speed)
vehicleNumAngX# = object angle x(objNum)
vehicleNumAngY# = object angle y(objNum)
vehicleNumAngZ# = object angle z(objNum)
value# = object angle x(fakeVehNum)
rotate object fakeVehNum, vehicleNumAngX#, vehicleNumAngY#, vehicleNumAngZ#
vehicleNumPosX# = object position x(objNum)
vehicleNumPosY# = object position y(objNum)
vehicleNumPosZ# = object position z(objNum)
position object fakeVehNum, vehicleNumPosX#, vehicleNumPosY#, vehicleNumPosZ#
move object fakeVehNum, speed
endfunction
I don't really want to explain everything, but I will describe to you the ODE commands.
ODE SET LINEAR VELOCITY objNum, x#, y#, Z#
This command apparantly moves the object in the specified x,y,z direction you want. Similar to
position object, except with a physics enabled twist.
ODE SET ANGULAR VELOCITY 2, 0, 2, 0
This command apparantly just rotates the object in any x,y,z angle you want. Similar to
rotate object, except with a physics enabled twist.
These two commands are central to the movement of the vehicle demonstrated in my code.
I hope to be back with more soon.
go to my website to download cool new games:
www.fishbrosentertainment.com