; ParticleCollision Example ; ------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-6 CameraClsColor camera,8,12,24 ; A Box3D physics world with a static slab for particles to bounce on world=CreatePhysicsWorld() slab=CreateCube() ScaleEntity slab,3,0.25,3 PositionEntity slab,0,0.25,0 EntityColor slab,55,60,72 slab_body=CreatePhysicsBody(world,slab,0) slab_shape=PhysicsBodyBox(slab_body,6,0.5,6,0) ; Sparks raining down onto the slab emitter=CreateParticleEmitter(600) PositionEntity emitter,0,3.5,0 ParticlePreset emitter,4 ParticleEmissionRate emitter,120 ParticleGravity emitter,0,-6,0 ; Enable swept collision against the physics world ParticleCollision emitter,world,0.04,0.65,0.15 colliding=True While Not KeyDown(1) ; Space toggles collision - pass zero as the world to disable it If KeyHit(57) colliding=Not colliding If colliding ParticleCollision emitter,world,0.04,0.65,0.15 Else ParticleCollision emitter,0,0,0,0 EndIf EndIf ; 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 ; UpdateWorld also advances the particle simulation UpdateWorld RenderWorld Text 0,0,"Arrow keys: move camera Space: toggle collision Esc: exit" If colliding Then state$="ParticleCollision emitter,world,0.04,0.65,0.15 (sparks bounce)" Else state$="ParticleCollision emitter,0,0,0,0 (sparks fall through)" Text 0,20,state$ Flip Wend FreePhysicsWorld world End