Blitz3D+ Command Reference

PhysicsWorldGetHitThreshold# ( world )

Parameters

world - live explicit physics world

Description

Returns the authored hit-event speed threshold in m/s, as a Float.

The default is 1. This reports a policy value, not a measurement of body motion or contact speed.

Contacts above this native approach-speed threshold can generate hit events when the participating shape event settings permit them. Changing this threshold does not change bounce impulses, begin/end events or current-contact query membership. Read hit events using CountPhysicsContacts(world,3) and the corresponding contact getters.

Reading this value does not change simulation state.

Ordinary world/body arguments must be live handles of the correct kind; invalid or stale handles raise a runtime error. Mutations are rejected while the owning world is stepping.

Requires Extended mode.

See also: PhysicsWorldHitThreshold, PhysicsWorldGetRestitutionThreshold, PhysicsWorldGetMaxSpeed, PhysicsWorldGetContactRecycleDistance.

Example

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

; Three test objects side by side, each with a different material
Dim things(3)
Dim bodies(3)
Dim shapes(3)
For i=1 To 3
    things(i)=CreateSphere(16)
    ScaleEntity things(i),0.4,0.4,0.4
    bodies(i)=CreatePhysicsBody(world,things(i),PHYSICS_DYNAMIC)
    shapes(i)=PhysicsBodySphere(bodies(i),0.8)
    EntityColor things(i),255,120,70

    ; Every ball is equally bouncy
    PhysicsShapeMaterialRestitution shapes(i),1,0.8
Next
Launch()

threshold#=1

While Not KeyDown(1)

    ; R launches them again
    If KeyHit(19) Then Launch()

    ; [ and ] change the approach speed needed for a hit event
    If KeyHit(26) And threshold>1 Then threshold=threshold-1
    If KeyHit(27) Then threshold=threshold+1
    PhysicsWorldHitThreshold world,threshold
    StepPhysics world,1.0/60.0,4

    ; Count the hit events from each step
    hits=hits+CountPhysicsContacts(world,3)

    ; 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: launch again   [ / ]: threshold   Esc: exit"
    Text 0,20,"PhysicsWorldGetHitThreshold(world) = "+PhysicsWorldGetHitThreshold(world)+" m/s"
    Text 0,40,"Hit events so far: "+hits

    Flip

Wend

FreePhysicsWorld world
End

Function Launch()
    For i=1 To 3
        ; Drop each ball from a different height, so they land at different speeds
        ResetPhysicsBody bodies(i),i*2-4,i*1.5,0,0,0,0
    Next
End Function

Index