Blitz3D+ Command Reference

PhysicsBodyMaxZ# ( body )

Parameters

body - body handle

Description

Returns the maximum world-space Z coordinate of the current native body AABB, in metres.

Native bounds include speculative collision padding and need not coincide with visible mesh bounds. The body box is the union of all attached shapes, including sensors. An empty body returns a zero-size box at its native origin. Supports all current shape kinds, including static mesh/terrain, and disabled bodies. This reads current bounds immediately; it does not create a query snapshot or apply query filters. Invalid/stale/wrong-kind handles raise runtime errors.

Requires Extended mode.

See also: CreatePhysicsQuery, QueryPhysicsBodyClosestPoint, QueryPhysicsShapeDistance, PhysicsQueryDistance, PhysicsQueryHasPoint.

Example

; PhysicsBodyMaxZ 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 crate with a ball fixed on top: one body, two shapes
cargo=CreatePivot()
crate=CreateCube(cargo)
ScaleEntity crate,0.5,0.5,0.5
EntityColor crate,255,120,70
ball=CreateSphere(12,cargo)
ScaleEntity ball,0.4,0.4,0.4
PositionEntity ball,0,0.9,0
EntityColor ball,120,220,120
cargo_body=CreatePhysicsBody(world,cargo,PHYSICS_DYNAMIC)
crate_shape=PhysicsBodyBox(cargo_body,1,1,1)
ball_shape=PhysicsBodySphere(cargo_body,0.8,1,0,0.9,0)
ResetPhysicsBody cargo_body,0,2,0,0.4,0.3,0.2

; A see-through yellow box shows the bounds
bounds=CreateCube()
EntityColor bounds,255,230,60
EntityAlpha bounds,0.3

While Not KeyDown(1)

    ; Space tosses the body, R drops it again
    If KeyHit(57)
        PhysicsBodyImpulse cargo_body,0,6,0
        PhysicsBodyAngularImpulse cargo_body,1,0,0.5
    EndIf
    If KeyHit(19) Then ResetPhysicsBody cargo_body,0,2,0,0.4,0.3,0.2

    StepPhysics world,1.0/60.0,4

    ; The body's world-space bounds enclose both of its shapes
    min_x#=PhysicsBodyMinX(cargo_body)
    min_y#=PhysicsBodyMinY(cargo_body)
    min_z#=PhysicsBodyMinZ(cargo_body)
    max_x#=PhysicsBodyMaxX(cargo_body)
    max_y#=PhysicsBodyMaxY(cargo_body)
    max_z#=PhysicsBodyMaxZ(cargo_body)
    PositionEntity bounds,(min_x+max_x)/2,(min_y+max_y)/2,(min_z+max_z)/2
    ScaleEntity bounds,(max_x-min_x)/2,(max_y-min_y)/2,(max_z-min_z)/2

    ; 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: toss   R: reset   Esc: exit"
    Text 0,20,"PhysicsBodyMaxZ(cargo_body) = "+max_z
    Text 0,40,"(max X "+max_x+", Y "+max_y+")"
    Text 0,60,"Both shapes fit inside the world-aligned box"

    Flip

Wend

FreePhysicsWorld world
End

Index