Blitz3D+ Command Reference

PhysicsCapsulePointX# ( shape,point )

Parameters

shape - live physics shape handle

point - capsule endpoint 1 or 2

Description

Returns the body-local X coordinate of capsule endpoint point, in metres. point must be 1 or 2.

These are the centres of the two hemispherical ends, excluding the radius; they retain the supplied endpoint ordering. Coincident endpoints are allowed. Wrong shape kinds and endpoint indices raise a runtime error.

This is read-only. Wrong-kind/stale handles and unsupported typed inspections raise runtime errors. Frame/dimension authoring metadata is wrapper state; native geometry effects are recorded, but physics replay does not reconstruct editable source entities.

Requires Extended mode.

See also: PhysicsShapeSphere, PhysicsShapeCapsule, PhysicsShapeBox, RefreshPhysicsHull, RefreshPhysicsMesh, PhysicsShapeRadius.

Example

; PhysicsCapsulePointX 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)

; An empty pivot carries the body; a child mesh shows its collider
root=CreatePivot()
body=CreatePhysicsBody(world,root,PHYSICS_DYNAMIC)

; A capsule: a cylinder with a ball on each end
half#=0.5
model=CreateCylinder(16,True,root)
EntityColor model,255,120,70
cap_a=CreateSphere(16,root)
cap_b=CreateSphere(16,root)
EntityColor cap_a,255,120,70
EntityColor cap_b,255,120,70
ScaleEntity cap_a,0.4,0.4,0.4
ScaleEntity cap_b,0.4,0.4,0.4
ScaleEntity model,0.4,half,0.4
PositionEntity cap_a,0,-half,0
PositionEntity cap_b,0,half,0

; A 1.8 m capsule: a 1 m segment plus the 0.8 m diameter
shape=PhysicsBodyCapsule(body,0.8,1.8)
ResetPhysicsBody body,0,2,0,0,0,0

While Not KeyDown(1)

    ; Space tosses the body, R drops it again
    If KeyHit(57)
        PhysicsBodyImpulse body,0,5,0
        PhysicsBodyAngularImpulse body,0.5,0,0.5
    EndIf
    If KeyHit(19) Then ResetPhysicsBody body,0,2,0,0,0,0

    ; [ and ] lengthen or shorten the capsule between its two end points
    change=KeyHit(27)-KeyHit(26)
    If change<>0
        half=half+change*0.25
        If half<0 Then half=0
        PhysicsShapeCapsule shape,0.8,0,-half,0,0,half,0
        ScaleEntity model,0.4,half,0.4
        PositionEntity cap_a,0,-half,0
        PositionEntity cap_b,0,half,0
    EndIf
    StepPhysics world,1.0/60.0,4

    ; 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   [ / ]: length   Esc: exit"
    Text 0,20,"PhysicsCapsulePointX(shape,1) = "+PhysicsCapsulePointX(shape,1)+"   (,2) = "+PhysicsCapsulePointX(shape,2)
    Text 0,40,"(Y "+PhysicsCapsulePointY(shape,1)+" and "+PhysicsCapsulePointY(shape,2)+")"

    Flip

Wend

FreePhysicsWorld world
End

Index