| None. |
|
Creates a new physics simulation world and returns its handle. A physics world is an independent Box3D simulation. It owns every body, shape and joint you create in it, and knows nothing about any other world. Most games create one world at startup, add a static body for the level plus dynamic bodies for the props, and then step the world once per frame. Nothing in a physics world moves until you call StepPhysics - UpdateWorld and RenderWorld never advance it, and it is completely separate from Blitz3D's built-in Collisions system. Box3D works in metres, kilograms and seconds, so a human-sized character is about 2 units tall. A new world starts with gravity 0,-10,0 and a worker count of 1. Use PhysicsGravity to change gravity (0,-9.81,0 for Earth-like feel). A world always steps on the thread that calls StepPhysics, one task after another: a higher PhysicsWorkers count reserves more storage but does not spread a big scene across CPU cores. When you are done, FreePhysicsWorld destroys the world together with everything it owns. See also: PhysicsGravity, StepPhysics, CreatePhysicsBody, PhysicsWorkers, FreePhysicsWorld. |
; CreatePhysicsWorld Example
; --------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
camera=CreateCamera()
PositionEntity camera,0,3,-9
light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 50,50,50
; Create an independent Box3D simulation world
world=CreatePhysicsWorld()
; Give the new world Earth-like gravity
PhysicsGravity world,0,-9.81,0
; Blue static ground slab
ground=CreateCube()
ScaleEntity ground,4,0.5,4
PositionEntity ground,0,-0.5,0,True
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,8,1,8,0)
; Bouncy orange ball to show the world simulating
ball=CreateSphere()
ScaleEntity ball,0.5,0.5,0.5
PositionEntity ball,0,4,0,True
EntityColor ball,255,120,70
ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC)
ball_shape=PhysicsBodySphere(ball_body,1,1)
PhysicsShapeRestitution ball_shape,0.7
While Not KeyDown(1)
; Space throws the ball back up
If KeyHit(57) Then PhysicsBodyVelocity ball_body,0,7,0
; Physics worlds only advance when StepPhysics is called
StepPhysics world,1.0/60.0,4
; Arrow keys move the camera
If KeyDown(200) Then MoveEntity camera,0,0,0.1
If KeyDown(208) Then MoveEntity camera,0,0,-0.1
If KeyDown(203) Then TurnEntity camera,0,1,0
If KeyDown(205) Then TurnEntity camera,0,-1,0
RenderWorld
Text 0,0,"Arrow keys: move camera Space: throw ball up Esc: exit"
Text 0,20,"World handle: "+world+" (stepped 60 times per second)"
Flip
Wend
FreePhysicsWorld world
FreeEntity ball
FreeEntity ground
End