Blitz3D+ Command Reference

PhysicsBodyTorque body,x#,y#,z#

Parameters

body - live explicit physics body handle

x# - world-space coordinate or vector component; see units below
y# - world-space coordinate or vector component; see units below
z# - world-space coordinate or vector component; see units below

Description

Applies a world-space torque in newton-metres without adding linear momentum.

Apply before each StepPhysics while torque acts. Wakes the dynamic body and its connected island; static, kinematic and disabled bodies do not respond. Components must be finite.

Ordinary accessors and setters reject stale or wrong-kind handles. Physics objects are owned by their world; deleting a body, entity tree or world also invalidates its dependent handles.

Requires Extended mode.

See also: CreatePhysicsBody, PhysicsBodyImpulseAt, StepPhysics.

Example

; PhysicsBodyTorque 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)

; An orange plank to push around
plank=CreateCube()
ScaleEntity plank,1.5,0.25,0.5
EntityColor plank,255,120,70
plank_body=CreatePhysicsBody(world,plank,PHYSICS_DYNAMIC)
plank_shape=PhysicsBodyBox(plank_body,3,0.5,1)
ResetPhysicsBody plank_body,0,1,0,0,0,0

While Not KeyDown(1)

    ; R puts the plank back in the middle
    If KeyHit(19) Then ResetPhysicsBody plank_body,0,1,0,0,0,0

    ; Hold Space to twist the plank about the vertical axis
    If KeyDown(57) Then PhysicsBodyTorque plank_body,0,12,0
    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   R: reset   Hold Space: twist   Esc: exit"
    Text 0,20,"PhysicsBodyTorque plank_body,0,12,0 while Space is held"
    Text 0,40,"Spin: "+PhysicsBodyAngularVelocityY(plank_body)+" radians per second"

    Flip

Wend

FreePhysicsWorld world
End

Index