| body - live physics body handle |
|
Returns the configured angular motion-lock mask. Sets independent world-axis translation and rotation masks: X=1, Y=2, Z=4; combine by addition or Or. Zero unlocks all axes, seven locks all. Both masks must be in 0..7 and are validated together before mutation. Clears velocity on newly locked axes, including paused motion, and wakes enabled bodies. Native mass/inertia is recomputed when the all-rotation lock changes. Stale/wrong-kind handles and invalid numeric inputs cause runtime errors. Object ownership is unchanged by these controls. See also: ResetPhysicsBody, PhysicsBodyActive, PhysicsBodyMode, StepPhysics. |
; PhysicsBodyAngularLocks 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 green static ramp
ramp=CreateCube()
ScaleEntity ramp,3,0.2,1.5
RotateEntity ramp,0,0,-20
PositionEntity ramp,0,1,0
EntityColor ramp,120,200,140
ramp_body=CreatePhysicsBody(world,ramp,PHYSICS_STATIC)
ramp_shape=PhysicsBodyBox(ramp_body,6,0.4,3)
; A crate dropped onto the top of the ramp
crate=CreateCube()
ScaleEntity crate,0.4,0.4,0.4
crate_body=CreatePhysicsBody(world,crate,PHYSICS_DYNAMIC)
crate_shape=PhysicsBodyBox(crate_body,0.8,0.8,0.8)
ResetPhysicsBody crate_body,-2,4,0,0,0,0.3
While Not KeyDown(1)
; R drops the crate again
If KeyHit(19) Then ResetPhysicsBody crate_body,-2,4,0,0,0,0.3
; Space cycles the locks: none, no turning, then straight down only
If KeyHit(57)
locks=(locks+1) Mod 3
If locks=0 Then PhysicsBodyMotionLocks crate_body,0,0
If locks=1 Then PhysicsBodyMotionLocks crate_body,0,7
If locks=2 Then PhysicsBodyMotionLocks crate_body,1+4,7
EndIf
StepPhysics world,1.0/60.0,4
; Orange while awake, grey once asleep
If PhysicsBodyIsAwake(crate_body)
EntityColor crate,255,120,70
Else
EntityColor crate,150,150,150
EndIf
; 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: drop again Space: change locks Esc: exit"
Text 0,20,"PhysicsBodyAngularLocks(crate_body) = "+PhysicsBodyAngularLocks(crate_body)
Text 0,40,"(linear "+PhysicsBodyLinearLocks(crate_body)+", angular "+PhysicsBodyAngularLocks(crate_body)+"; X=1, Y=2, Z=4)"
Flip
Wend
FreePhysicsWorld world
End