Tutorials › dbpro Professional
Physics
Balls fall, roll down two ramps and pile up, with no movement code of your own.
The ODE commands
OpenDBC runs 87 forms of the DarkBASIC Professional ODE extension on Jolt Physics. You make objects as usual, then hand them to the physics engine.
Static and dynamic
A static body never moves but others collide with it: floors, walls, ramps. A dynamic body is moved by the simulation: gravity, bounces, rolling. The body takes the shape, position and rotation of its object at creation.
ode start
ode set world gravity 0, -20, 0
ode create static box 1
ode create dynamic sphere 10See ODE START, ODE SET WORLD GRAVITY, ODE CREATE STATIC BOX and
ODE CREATE DYNAMIC SPHERE.
Step the world
ODE UPDATE advances the simulation and moves the dynamic objects. Call it once per frame,
before SYNC.
rem Physics - OpenDBC tutorial (DarkBASIC Professional)
sync on : sync rate 60
autocam off
color backdrop rgb(18, 20, 34)
rem The ground and two ramps are static: they never move
make object box 1, 120, 2, 80
position object 1, 0, -1, 0
color object 1, rgb(70, 80, 110)
make object box 2, 40, 2, 30
position object 2, -20, 18, 0 : zrotate object 2, -20
color object 2, rgb(200, 120, 60)
make object box 3, 40, 2, 30
position object 3, 20, 8, 0 : zrotate object 3, 20
color object 3, rgb(200, 120, 60)
ode start
ode set world gravity 0, -20, 0
for n = 1 to 3
ode create static box n
next n
rem Balls are dynamic: the physics engine moves them
ball = 10
position camera 0, 30, -90
point camera 0, 10, 0
do
rem Drop a new ball every half second, up to 30
if timer() - last > 500 and ball < 40
last = timer()
make object sphere ball, 4
color object ball, rgb(rnd(155) + 100, rnd(155) + 100, 255)
position object ball, -30 + rnd(8), 40, rnd(10) - 5
ode create dynamic sphere ball
inc ball
endif
ode update
text 10, 10, "Balls: " + str$(ball - 10)
sync
loopTry this
- Throw a ball:
ODE SET LINEAR VELOCITYright after creating it. - Make the ramps slippery with
ODE SET BODY FRICTION. - Remove balls that fall off with
ODE DESTROY OBJECTandDELETE OBJECT.
Boxes, spheres, capsules, cylinders and triangle meshes, forces, collision messages, rays, joints and a character controller are available. Ragdolls, static terrains and the contact modes of ODE's own solver are not. The reference lists every form.