; Physics contacts example (an ArcBasic extension) ; Balls rain onto blocks; a block lights up when it is hit hard Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,8,-14 TurnEntity camera,25,0,0 light=CreateLight() RotateEntity light,50,30,0 ground=CreatePlane() EntityColor ground,60,60,60 EntityPhysics ground,1 Dim block(4) For i=0 To 4 block(i)=CreateCube() PositionEntity block(i),i*2.5-5,1,0 EntityPhysics block(i),1 Next marker=CreateSphere(6) ScaleEntity marker,.15,.15,.15 EntityColor marker,255,0,0 While Not KeyHit(1) If Rand(0,10)=0 And balls<150 balls=balls+1 ball=CreateSphere(8) ScaleEntity ball,.3,.3,.3 PositionEntity ball,Rnd(-6,6),8,Rnd(-.5,.5) EntityPhysics ball,2 EntityBounce ball,.5 EndIf UpdateWorld For i=0 To 4 EntityColor block(i),120,120,160 For c=1 To CountContacts(block(i)) If ContactImpulse(block(i),c)>1 EntityColor block(i),255,220,80 ; show where it was hit PositionEntity marker,ContactX(block(i),c),ContactY(block(i),c),ContactZ(block(i),c) ; ContactEntity is the ball that hit it: turn it red EntityColor ContactEntity(block(i),c),255,60,60 ; the normal points away from the ball, so down for a hit on top If ContactNY(block(i),c)<-.5 Then hits=hits+1 EndIf Next Next RenderWorld Text 0,0,"Hits on top of the blocks: "+hits Flip Wend End