|
joint - a current physics joint handle lower# - finite lower signed spring force in newtons upper# - finite upper signed spring force in newtons |
|
Sets the signed force range of a distance spring in newtons. Both limits must be finite and lower must not exceed upper. Negative force is tension (pulls B toward A); positive force is compression (pushes B away from A). For example, -2,3 allows at most 2 N tension and 3 N compression; -10,0 is tension-only; 0,0 disables spring force. This caps only the soft spring, not the distance motor, limits or rigid constraint. Enable the spring with PhysicsJointSpring; a disabled spring restores the rigid distance constraint. The command wakes connected bodies. Hinge/slider/ball/fixed joints are rejected. Invalid, stale or wrong-kind handles raise a runtime error. See also: PhysicsJointSpring, PhysicsJointFrame, PhysicsJointThresholds, PhysicsJointEventJoint, StepPhysics. |
; PhysicsJointSpringForceRange Example
; ------------------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
camera=CreateCamera()
PositionEntity camera,0,3,-10
RotateEntity camera,0,0,0
light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 60,60,60
; An independent Box3D world with standard gravity
world=CreatePhysicsWorld()
; Blue static floor
ground=CreateCube()
ScaleEntity ground,6,0.5,6
PositionEntity ground,0,-0.5,0
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,12,1,12)
; A static beam, and a heavy ball hanging from its left end on a springy rope
beam=CreateCube()
ScaleEntity beam,1.5,0.15,0.3
PositionEntity beam,0,5,0
EntityColor beam,150,150,160
beam_body=CreatePhysicsBody(world,beam,PHYSICS_STATIC)
beam_shape=PhysicsBodyBox(beam_body,3,0.3,0.6)
ball=CreateSphere(16)
ScaleEntity ball,0.3,0.3,0.3
PositionEntity ball,-1.5,3,0
EntityColor ball,255,120,70
ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC)
ball_shape=PhysicsBodySphere(ball_body,0.6,20)
rope=CreatePhysicsDistanceJoint(beam_body,ball_body,-1.5,5,0,-1.5,3,0)
PhysicsJointSpring rope,True,1.5,0.1
tension#=400
While Not KeyDown(1)
; Space throws the ball sideways, so it swings up past the beam
If KeyHit(57) Then PhysicsBodyImpulse ball_body,25,0,0
; [ and ] change how hard the spring may pull, in newtons of tension
If KeyHit(26) And tension>10 Then tension=tension-10
If KeyHit(27) Then tension=tension+10
PhysicsJointSpringForceRange rope,-tension,1000
StepPhysics world,1.0/60.0,4
; 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
; Draw the rope
CameraProject camera,-1.5,5,0
beam_x=ProjectedX()
beam_y=ProjectedY()
CameraProject camera,EntityX(ball),EntityY(ball),EntityZ(ball)
Line beam_x,beam_y,ProjectedX(),ProjectedY()
Text 0,0,"Arrow keys: move camera Space: throw [ / ]: max tension Esc: exit"
Text 0,20,"PhysicsJointSpringForceRange rope,"+(-tension)+",1000"
Text 0,40,"A weak spring cannot hold up the 2.3 kg ball, so it sags"
Flip
Wend
FreePhysicsWorld world
End