PhysicsJointSpringUpperForce# ( joint )
Parameters
| joint - a current physics joint handle |
Description
|
Returns the distance spring's configured upper signed force bound in newtons. Negative means tension; positive means compression. Native defaults are -FLT_MAX and FLT_MAX (effectively uncapped). This is a spring-only bound, not a measured force or a total constraint cap. Other joint families are rejected. Invalid, stale or wrong-kind handles raise a runtime error. Requires Extended mode. See also: PhysicsJointSpring, PhysicsJointFrame, PhysicsJointThresholds, PhysicsJointEventJoint, StepPhysics. |
Example
; PhysicsJointSpringUpperForce Example ; ------------------------------------ ; Requires Extended mode. 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,"PhysicsJointSpringUpperForce(rope) = "+PhysicsJointSpringUpperForce(rope)+" N" Text 0,40,"(positive is compression; lower bound "+PhysicsJointSpringLowerForce(rope)+" N)" Flip Wend FreePhysicsWorld world End
Index