Blitz3D+ Command Reference

PhysicsContactShapeB ( world,event_type,index )

Parameters

world - physics-world handle returned by CreatePhysicsWorld

event_type - contact list to read: 1 begin, 2 end, or 3 hit

index - 1-based position in that list, up to CountPhysicsContacts

Description

Returns the second of the two shapes in a contact event.

The partner of PhysicsContactShapeA: together they name the pair of shapes that started touching, stopped touching or hit. Match the handles against the shapes you created to identify the objects involved, and check both sides - which shape is A and which is B carries no meaning.

The event lists are a snapshot from the most recent StepPhysics call and are replaced by the next one, so read them between steps.

Requires Extended mode.

See also: CountPhysicsContacts, PhysicsContactShapeA, PhysicsContactX, PhysicsContactSpeed, StepPhysics.

Example

; PhysicsContactShapeB Example
; ----------------------------
; Requires Extended mode.

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
Const PHYSICS_CONTACT_HIT=3

camera=CreateCamera()
PositionEntity camera,0,3,-6

light=CreateLight()
RotateEntity light,45,-30,0
AmbientLight 50,50,50

world=CreatePhysicsWorld()
PhysicsGravity world,0,-9.81,0

; Static ground slab for the ball to bounce on
ground=CreateCube()
ScaleEntity ground,4,0.5,4
PositionEntity ground,0,-0.5,5,True
EntityColor ground,80,160,255
ground_body=CreatePhysicsBody(world,ground,PHYSICS_STATIC)
ground_shape=PhysicsBodyBox(ground_body,8,1,8,0)

; Bouncy dynamic ball dropped from above
ball=CreateSphere()
ScaleEntity ball,0.5,0.5,0.5
PositionEntity ball,0,4,5,True
EntityColor ball,255,120,70
ball_body=CreatePhysicsBody(world,ball,PHYSICS_DYNAMIC)
ball_shape=PhysicsBodySphere(ball_body,1,1)
PhysicsShapeRestitution ball_shape,0.7

; Yellow marker highlights the latest contact point
marker=CreateSphere(8)
ScaleEntity marker,0.15,0.15,0.15
EntityColor marker,255,255,0
HideEntity marker

hits=0

While Not KeyDown(1)

    ; Space kicks the ball back up so fresh contacts keep happening
    If KeyHit(57) Then PhysicsBodyImpulse ball_body,0,3,0

    StepPhysics world,1.0/60.0,4

    ; Read the first hit-contact snapshot recorded during this step
    If CountPhysicsContacts(world,PHYSICS_CONTACT_HIT)>0
        hit_x#=PhysicsContactX(world,PHYSICS_CONTACT_HIT,1)
        hit_y#=PhysicsContactY(world,PHYSICS_CONTACT_HIT,1)
        hit_z#=PhysicsContactZ(world,PHYSICS_CONTACT_HIT,1)
        normal_x#=PhysicsContactNX(world,PHYSICS_CONTACT_HIT,1)
        normal_y#=PhysicsContactNY(world,PHYSICS_CONTACT_HIT,1)
        normal_z#=PhysicsContactNZ(world,PHYSICS_CONTACT_HIT,1)
        speed#=PhysicsContactSpeed(world,PHYSICS_CONTACT_HIT,1)
        shape_a=PhysicsContactShapeA(world,PHYSICS_CONTACT_HIT,1)
        shape_b=PhysicsContactShapeB(world,PHYSICS_CONTACT_HIT,1)
        hits=hits+1
        PositionEntity marker,hit_x,hit_y,hit_z,True
        ShowEntity marker
    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   Space: kick the ball   Esc: exit"
    Text 0,20,"PhysicsContactShapeB(world,3,1) = "+shape_b+"   ball_shape="+ball_shape+" ground_shape="+ground_shape
    Text 0,40,"Hit point: "+hit_x+", "+hit_y+", "+hit_z+"   Normal: "+normal_x+", "+normal_y+", "+normal_z
    Text 0,60,"Approach speed: "+speed+"   Hit contacts seen: "+hits

    Flip

Wend

FreePhysicsWorld world
End

Index