Blitz3D+ Command Reference

PhysicsShapeMaxZ# ( shape )

Parameters

shape - shape handle

Description

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

Native bounds include speculative collision padding and need not coincide with visible mesh bounds. The bound includes the collider's authored local geometry and current body transform. 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

; PhysicsShapeMaxZ 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 crate shape's world-space bounds grow as it tilts
    min_x#=PhysicsShapeMinX(crate_shape)
    min_y#=PhysicsShapeMinY(crate_shape)
    min_z#=PhysicsShapeMinZ(crate_shape)
    max_x#=PhysicsShapeMaxX(crate_shape)
    max_y#=PhysicsShapeMaxY(crate_shape)
    max_z#=PhysicsShapeMaxZ(crate_shape)
    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,"PhysicsShapeMaxZ(crate_shape) = "+max_z
    Text 0,40,"(max X "+max_x+", Y "+max_y+")"
    Text 0,60,"Only the crate shape is boxed; the ball is not"

    Flip

Wend

FreePhysicsWorld world
End

Index