; Physics joints example (an ArcBasic extension) ; A door on a hinge, a chain of pins, a weight on a spring and a glued pair. ; Space gives everything a shove. C lets the door hit its frame, D shows shapes Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,5,-15 TurnEntity camera,12,0,0 light=CreateLight() RotateEntity light,50,30,0 ground=CreatePlane() EntityColor ground,70,90,70 EntityPhysics ground,1 ; a door: a hinge on its left edge, joined to the world (entity2 = 0) frame=CreateCube() ScaleEntity frame,.1,1.5,.1 PositionEntity frame,-7,1.5,0 EntityPhysics frame,1 door=CreateCube() ScaleEntity door,1,1.4,.08 PositionEntity door,-5.9,1.5,0 EntityColor door,160,110,60 EntityPhysics door,2,3 hinge=HingeJoint(door,0,-6.9,1.5,0,0,1,0) ; a chain: each link pinned to the one above, the first to the world Dim link(6) For i=0 To 6 link(i)=CreateSphere(8) ScaleEntity link(i),.2,.2,.2 PositionEntity link(i),-1+i*.42,7,0 EntityPhysics link(i),2,.3 If i=0 PinJoint link(0),0,-1.2,7,0 Else PinJoint link(i),link(i-1),-1+i*.42-.21,7,0 EndIf Next ; a weight on a spring that can only move up and down weight=CreateCube() ScaleEntity weight,.5,.5,.5 PositionEntity weight,4,4,0 EntityColor weight,90,160,255 EntityPhysics weight,2,2 spring=SpringJoint(weight,0,0,1,0,60,1) ; two crates glued into one a=CreateCube() : ScaleEntity a,.5,.5,.5 : PositionEntity a,7,3,0 : EntityPhysics a,2 b=CreateCube() : ScaleEntity b,.5,.5,.5 : PositionEntity b,7.5,3.9,0 : EntityPhysics b,2 EntityColor b,255,200,80 FixedJoint b,a collide=False debug=False While Not KeyHit(1) If KeyHit(57) ApplyImpulse door,0,0,4,1,0,0 ApplyImpulse link(6),3,0,0 ApplyImpulse weight,0,-6,0 ApplyImpulse a,0,6,0,.5,0,0 EndIf If KeyHit(46) Then collide=Not collide : JointCollide hinge,collide If KeyHit(32) Then debug=Not debug : PhysicsDebug debug UpdateWorld RenderWorld Text 0,0,"Space: shove C: door collides with its frame D: shapes" Text 0,15,"Door angle: "+Int(JointPosition(hinge))+" spring stretch: "+JointPosition(spring) Flip Wend End