; Collisions Example ; ------------------ Graphics3D 640,480,0,2 SetBuffer BackBuffer() ; Collision type ids type_player=1 type_scenery=2 ; NOTE: fixed overhead camera - the arrow keys steer the PLAYER, not the camera camera=CreateCamera() PositionEntity camera,0,13,-13 RotateEntity camera,45,0,0 light=CreateLight() RotateEntity light,60,30,0 floor=CreatePlane() EntityColor floor,70,110,70 ; The player ball is the collision SOURCE, so it needs an ellipsoid radius player=CreateSphere() EntityColor player,220,60,60 PositionEntity player,0,1,-4 EntityRadius player,1 EntityType player,type_player ; Three crates. They are given radius AND box data so that every collision ; method has the information it needs on the destination side. crate1=CreateCube() ScaleEntity crate1,1.2,1.2,1.2 PositionEntity crate1,-4,1.2,4 EntityColor crate1,200,160,60 EntityType crate1,type_scenery EntityRadius crate1,1.7 EntityBox crate1,-1.2,-1.2,-1.2,2.4,2.4,2.4 crate2=CreateCube() ScaleEntity crate2,1.2,1.2,1.2 PositionEntity crate2,0,1.2,4 EntityColor crate2,200,160,60 EntityType crate2,type_scenery EntityRadius crate2,1.7 EntityBox crate2,-1.2,-1.2,-1.2,2.4,2.4,2.4 crate3=CreateCube() ScaleEntity crate3,1.2,1.2,1.2 PositionEntity crate3,4,1.2,4 EntityColor crate3,200,160,60 EntityType crate3,type_scenery EntityRadius crate3,1.7 EntityBox crate3,-1.2,-1.2,-1.2,2.4,2.4,2.4 method=2 response=2 method_name$="ellipsoid-to-polygon" response_name$="slide" While Not KeyDown(1) ; Arrow keys steer the player ball If KeyDown(200) Then MoveEntity player,0,0,0.1 If KeyDown(208) Then MoveEntity player,0,0,-0.1 If KeyDown(203) Then MoveEntity player,-0.1,0,0 If KeyDown(205) Then MoveEntity player,0.1,0,0 ; M cycles the collision method, R cycles the response If KeyHit(50) method=method+1 If method>3 Then method=1 If method=1 Then method_name$="ellipsoid-to-ellipsoid" If method=2 Then method_name$="ellipsoid-to-polygon" If method=3 Then method_name$="ellipsoid-to-box" EndIf If KeyHit(19) response=response+1 If response>3 Then response=1 If response=1 Then response_name$="stop" If response=2 Then response_name$="slide" If response=3 Then response_name$="slide, but never down slopes" EndIf ; The star of the show: register collisions between the two types Collisions type_player,type_scenery,method,response ; UpdateWorld performs the collision checks and responses UpdateWorld RenderWorld Text 0,0,"Arrow keys: drive the ball M: method R: response Esc: exit" Text 0,20,"Collisions type_player,type_scenery,"+method+","+response Text 0,40,"Method "+method+": "+method_name$+" Response "+response+": "+response_name$ Text 0,60,"Brush a crate corner with each method - sphere, exact mesh or box" Flip Wend End