Blitz3D+ Command Reference

PhysicsBodyAngularVelocityX# ( body )

Parameters

body - physics-body handle returned by CreatePhysicsBody

Description

Returns the X component of a body's angular velocity.

The value is in radians per second about the world X axis (2*Pi is one full turn per second). A positive value is spin in the direction of increasing pitch, following the rotation senses described under PhysicsBodyAngularVelocity. Together with PhysicsBodyAngularVelocityY and PhysicsBodyAngularVelocityZ it gives the full spin vector - useful for spin-based effects, or for deciding when a rolling prop has effectively stopped.

Requires Extended mode.

See also: PhysicsBodyAngularVelocity, PhysicsBodyAngularVelocityY, PhysicsBodyAngularVelocityZ, PhysicsBodyVelocityX.

Example

; PhysicsBodyAngularVelocityX Example
; -----------------------------------
; Requires Extended mode.

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

Const PHYSICS_DYNAMIC=2

camera=CreateCamera()
PositionEntity camera,0,2,-7

light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 50,50,50

; Zero gravity keeps the tumbling capsule floating in place
world=CreatePhysicsWorld()
PhysicsGravity world,0,0,0

; Blue capsule whose spin you control
pill=CreateCylinder(16,True)
ScaleEntity pill,0.5,1.25,0.5
PositionEntity pill,0,1.5,0,True
EntityColor pill,80,180,255
pill_body=CreatePhysicsBody(world,pill,PHYSICS_DYNAMIC)
pill_shape=PhysicsBodyCapsule(pill_body,1,2.5,1)

; Start with a gentle spin about the Y axis
PhysicsBodyAngularVelocity pill_body,0,2,0

While Not KeyDown(1)

    ; Keys 1/2/3 set the spin about the X, Y or Z axis; Space stops it
    If KeyHit(2) Then PhysicsBodyAngularVelocity pill_body,3,0,0
    If KeyHit(3) Then PhysicsBodyAngularVelocity pill_body,0,3,0
    If KeyHit(4) Then PhysicsBodyAngularVelocity pill_body,0,0,3
    If KeyHit(57) Then PhysicsBodyAngularVelocity pill_body,0,0,0

    ; Advance the Box3D simulation by one 60 Hz step
    StepPhysics world,1.0/60.0,4

    ; Read back the live spin components in radians per second
    spin_x#=PhysicsBodyAngularVelocityX(pill_body)
    spin_y#=PhysicsBodyAngularVelocityY(pill_body)
    spin_z#=PhysicsBodyAngularVelocityZ(pill_body)

    ; 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,"1/2/3: spin axis   Space: stop   Arrow keys: camera   Esc: exit"
    Text 0,20,"Angular velocity X: "+spin_x+" rad/s"
    Text 0,40,"Angular velocity Y: "+spin_y+" rad/s"
    Text 0,60,"Angular velocity Z: "+spin_z+" rad/s"

    Flip

Wend

FreePhysicsWorld world
FreeEntity pill
End

Index