ArcBasicDocs

help/commands/3d_examples

JointCollide.abs

76 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.

Download JointCollide.absAll files in this folder

JointCollide.abs
; 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 shapesGraphics3D 640,480SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,5,-15TurnEntity camera,12,0,0light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,70,90,70EntityPhysics ground,1; a door: a hinge on its left edge, joined to the world (entity2 = 0)frame=CreateCube()ScaleEntity frame,.1,1.5,.1PositionEntity frame,-7,1.5,0EntityPhysics frame,1door=CreateCube()ScaleEntity door,1,1.4,.08PositionEntity door,-5.9,1.5,0EntityColor door,160,110,60EntityPhysics door,2,3hinge=HingeJoint(door,0,-6.9,1.5,0,0,1,0); a chain: each link pinned to the one above, the first to the worldDim 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	EndIfNext; a weight on a spring that can only move up and downweight=CreateCube()ScaleEntity weight,.5,.5,.5PositionEntity weight,4,4,0EntityColor weight,90,160,255EntityPhysics weight,2,2spring=SpringJoint(weight,0,0,1,0,60,1); two crates glued into onea=CreateCube() : ScaleEntity a,.5,.5,.5 : PositionEntity a,7,3,0 : EntityPhysics a,2b=CreateCube() : ScaleEntity b,.5,.5,.5 : PositionEntity b,7.5,3.9,0 : EntityPhysics b,2EntityColor b,255,200,80FixedJoint b,acollide=Falsedebug=FalseWhile 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)	FlipWendEnd