; PhysicsShapeFilter Example ; -------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_DYNAMIC=2 Const GROUND_CATEGORY=1 Const BALL_CATEGORY=2 camera=CreateCamera() PositionEntity camera,0,3,-6 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 50,50,50 world=CreatePhysicsWorld() PhysicsGravity world,0,-9.81,0 ; Static ground slab in collision category 1 ground=CreateCube() ScaleEntity ground,4,0.5,4 PositionEntity ground,0,-0.5,5,True EntityColor ground,80,160,255 ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC) ground_shape=PhysicsBodyBox(ground_body,8,1,8,0) PhysicsShapeFilter ground_shape,GROUND_CATEGORY,-1,0 ; A bouncy ball in collision category 2 ball=CreateSphere(16) ScaleEntity ball,0.5,0.5,0.5 PositionEntity ball,0,4,5,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 mask=-1 While Not KeyDown(1) ; Space toggles the mask: -1 collides with everything, 2 ignores the ground If KeyHit(57) If mask=-1 Then mask=BALL_CATEGORY Else mask=-1 EndIf ; Apply the current category and mask to the ball's shape PhysicsShapeFilter ball_shape,BALL_CATEGORY,mask,0 StepPhysics world,1.0/60.0,4 ; Re-drop the ball after it falls through the ground If EntityY(ball,True)<-6 FreePhysicsBody ball_body PositionEntity ball,0,4,5,True ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC) ball_shape=PhysicsBodySphere(ball_body,1,1) PhysicsShapeRestitution ball_shape,0.7 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 RenderWorld Text 0,0,"Space: toggle the ball's collision mask Arrows: camera Esc: exit" Text 0,20,"PhysicsShapeFilter ball_shape,"+BALL_CATEGORY+","+mask+",0" Text 0,40,"Mask -1 bounces on the ground; mask 2 falls straight through it" Flip Wend FreePhysicsWorld world End