PhysicsMotorJointAngularSpring joint,hertz#,damping_ratio#,maximum_torque#

Parameters

joint - a live general motor-joint handle

hertz# - finite non-negative spring frequency, Hertz

damping_ratio# - finite non-negative dimensionless damping ratio

maximum_torque# - finite non-negative vector torque cap, N m

Description

Configures a motor joint's orientation spring.

Sets the orientation spring frequency in Hertz, dimensionless damping ratio and maximum spring torque in N m. All values must be finite and non-negative. The spring tries to align frame B with frame A, using native quaternion rotation error. PhysicsJointFrame edits either local frame in Blitz Euler radians. Zero hertz or zero torque cap disables this spring and clears its cached impulse; it does not disable the independent angular velocity drive.

Setters validate every argument before mutation and wake connected bodies. Getters read configured settings, including those of disabled channels; they do not wake bodies or change physics. Invalid/stale/wrong-kind handles, unsupported joint families and non-finite or out-of-range arguments raise runtime errors. Freeing either body, its entity or the world also frees the joint. Use FreePhysicsJoint to release it without changing the body's pose or velocity.

The four channels have independent vector-magnitude caps. If a velocity drive and spring act together, the combined force or torque can reach the sum of their respective caps, or their efforts can oppose each other. They do not guarantee that a target speed or pose will be reached against collision, gravity or another constraint. PhysicsJointForceX/Y/Z and PhysicsJointTorqueX/Y/Z read combined reaction on body B; torque excludes the moment from force at the attachment point. Overload events are sampled in native bias solves, while public feedback describes the final substep's cached reaction.

Use PhysicsJointFrame joint,1,x,y,z,pitch,yaw,roll to edit the target frame relative to body A. Side 2 edits the driven attachment frame. Its component getters inspect either frame. Positions are in the body's unscaled local metres; rotations use physics radians in Blitz Euler order. Velocity targets remain world vectors. These settings, frame edits and native wake operations participate in physics recording/replay; recordings are not complete render-scene or input saves.


See also: CreatePhysicsMotorJoint, PhysicsMotorJointLinearSpring, PhysicsMotorJointLinearVelocity, PhysicsJointFrame.

Example

; PhysicsMotorJointAngularSpring Example
; --------------------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,3,-7
RotateEntity camera,20,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 kinematic "hand" you steer, and a crate it holds with a motor joint
hand=CreateSphere(12)
ScaleEntity hand,0.2,0.2,0.2
PositionEntity hand,0,2.5,0
EntityColor hand,255,230,60
hand_body=CreatePhysicsBody(world,hand,1)
crate=CreateCube()
ScaleEntity crate,0.4,0.4,0.4
PositionEntity crate,1.5,0.4,0
EntityColor crate,255,120,70
crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC)
crate_shape=PhysicsBodyBox(crate_body,0.8,0.8,0.8)
grab=CreatePhysicsMotorJoint(hand_body,crate_body)

; A position spring pulls the crate's origin to the hand
PhysicsMotorJointLinearSpring grab,3,0.7,200

; An orientation spring keeps the crate level with the hand
PhysicsMotorJointAngularSpring grab,3,0.7,50

While Not KeyDown(1)

    ; A and D move the hand sideways, W and S move it up and down
    If KeyDown(30) Then MoveEntity hand,-0.05,0,0
    If KeyDown(32) Then MoveEntity hand,0.05,0,0
    If KeyDown(17) Then MoveEntity hand,0,0.05,0
    If KeyDown(31) Then MoveEntity hand,0,-0.05,0

    ; O switches the orientation spring off, so the crate can swing and spin
    If KeyHit(24)
        level=Not level
        PhysicsMotorJointAngularSpring grab,3*level,0.7,50*level
    EndIf
    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

    Text 0,0,"Arrow keys: move camera   A / D / W / S: move the hand   O: orientation spring"
    Text 0,20,"Esc: exit"
    Text 0,40,"PhysicsMotorJointAngularSpring grab,"+3*level+",0.7,"+50*level
    Text 0,60,"Without it the crate swings and turns freely"

    Flip

Wend

FreePhysicsWorld world
End

Index