PhysicsBodyAngularVelocity body,x#,y#,z#
Parameters
|
body - physics-body handle returned by CreatePhysicsBody x# - spin about the world X axis, in radians per second y# - spin about the world Y axis z# - spin about the world Z axis |
Description
|
Sets a body's angular velocity (spin) directly. The vector is the spin axis and its length is the spin rate: 0,6.283,0 is one full turn per second about Y. Note the units - unlike most Blitz3D rotation commands this is radians per second, not degrees (2*Pi radians is a full turn). The spin senses follow the world axes of the 3D maths commands such as TFormVector, which is not quite the Euler convention: positive x and z spins increase pitch and roll, but a positive y spin turns the body in the direction of decreasing yaw, because Blitz3D measures yaw in the opposite sense to a positive rotation about the world Y axis. To spin a body the way positive TurnEntity yaw turns it, pass a negative y component - worth knowing before steering a body's yaw with this command. Perfect for tossing crates with a tumble, spinning thrown weapons, or giving debris a believable scatter. Setting a non-zero spin wakes a sleeping body, collisions and PhysicsBodyDamping will slow it down over time, and static bodies ignore it. Read the current spin back with PhysicsBodyAngularVelocityX, PhysicsBodyAngularVelocityY and PhysicsBodyAngularVelocityZ. Requires Extended mode. See also: PhysicsBodyAngularVelocityX, PhysicsBodyAngularVelocityY, PhysicsBodyAngularVelocityZ, PhysicsBodyVelocity, PhysicsBodyDamping. |
Disabled bodies
| When PhysicsBodyActive disables a body, its velocity is preserved. Velocity setters edit that paused motion; velocity getters, including point velocity, return the motion that will resume when the body is re-enabled. PhysicsBodyAwake does not re-enable a disabled body. Static bodies still have zero velocity. |
Example
; PhysicsBodyAngularVelocity 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