Blitz3D+ Command Reference

PhysicsJointFrame joint,side,x#,y#,z#,pitch#,yaw#,roll#

Parameters

joint - a current physics joint handle

side - 1 for body A; 2 for body B

x# - body-local X in metres
y# - body-local Y in metres
z# - body-local Z in metres

pitch# - body-local pitch in radians

yaw# - body-local yaw in radians

roll# - body-local roll in radians

Description

Replaces one local attachment frame and wakes the connected bodies.

Side 1 selects body A; side 2 selects body B. Position is in metres in that body's unscaled local coordinates; pitch, yaw and roll are Blitz rotations in radians. Every component must be finite. This changes anchors and reference axes without teleporting bodies, and can introduce a constraint error corrected on later steps. Distance uses the positions; slider travel follows frame A's X axis; hinge twist follows frame A's Z axis. Wheel suspension and steering follow frame A's X axis, while wheel spin follows frame B's Z axis. Motor-joint springs try to align frame B with frame A; editing frame A changes the target relative to body A, while editing frame B changes the driven attachment. Existing world-anchor constructors remain unchanged.

Invalid, stale or wrong-kind handles raise a runtime error.

Requires Extended mode.

See also: PhysicsJointSpring, PhysicsJointThresholds, PhysicsJointEventJoint, StepPhysics.

Example

; PhysicsJointFrame 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,-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 static post, and a door hinged to it on a vertical axis
post=CreateCube()
ScaleEntity post,0.1,1.5,0.1
PositionEntity post,-1.5,1.5,0
EntityColor post,150,150,160
post_body=CreatePhysicsBody(world,post,PHYSICS_STATIC)
post_shape=PhysicsBodyBox(post_body,0.2,3,0.2)
door=CreateCube()
ScaleEntity door,1.2,1.4,0.05
PositionEntity door,-0.2,1.5,0
EntityColor door,255,120,70
door_body=CreatePhysicsBody(world,door,PHYSICS_DYNAMIC)
door_shape=PhysicsBodyBox(door_body,2.4,2.8,0.1)
PhysicsBodyDamping door_body,0,1
hinge=CreatePhysicsHingeJoint(post_body,door_body,-1.4,1.5,0,0,1,0)

While Not KeyDown(1)

    ; Space pushes the far edge of the door
    If KeyHit(57)
        TFormPoint 1,0,0,door,0
        PhysicsBodyImpulseAt door_body,0,0,2,TFormedX(),TFormedY(),TFormedZ()
    EndIf

    ; F moves the door's attachment point between its edge and its middle
    If KeyHit(33)
        middle=Not middle
        local_x#=-1.2
        If middle Then local_x=0
        PhysicsJointFrame hinge,2,local_x,PhysicsJointFrameY(hinge,2),PhysicsJointFrameZ(hinge,2),PhysicsJointFramePitch(hinge,2),PhysicsJointFrameYaw(hinge,2),PhysicsJointFrameRoll(hinge,2)
    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   Space: push   F: move the hinge point   Esc: exit"
    Text 0,20,"Door attachment at local X "+PhysicsJointFrameX(hinge,2)
    Text 0,40,"At X 0 the door turns about its middle, like a revolving door"

    Flip

Wend

FreePhysicsWorld world
End

Index