|
world - world handle index - one-based body-event index |
|
Returns the signed application body tag captured at the event step. Later tag edits or body deletion do not change it. Body event capture is opt-in per world. The copied batch is replaced after each StepPhysics; it is independent of held query snapshots. Awake dynamic and kinematic bodies can emit entries, including zero-motion awake bodies; static bodies do not. A fell-asleep entry marks that transition, and sleeping bodies normally leave the stream. Entries are sorted by wrapper body handle, not creation order. Tags and final native world poses are copied after continuous-collision correction; after deletion live body/entity getters return zero. Event indices belong to one step. A kinematic native pose can differ from its authored entity target while integration approaches it. Invalid/stale/wrong-kind handles, invalid indices or unavailable payload fields raise runtime errors. See also: QueryPhysicsBodyContacts, QueryPhysicsShapeContacts, QueryPhysicsSensor, CountPhysicsQueryManifolds, PhysicsBodyEvents. |
; PhysicsBodyEventTag Example
; ---------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
Const PHYSICS_STATIC=0
Const PHYSICS_DYNAMIC=2
Const CRATE_COUNT=12
SeedRnd MilliSecs()
camera=CreateCamera()
PositionEntity camera,0,6,-12
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 pile of crates, dropped from random heights
Dim crates(CRATE_COUNT)
Dim crate_bodies(CRATE_COUNT)
For i=1 To CRATE_COUNT
crates(i)=CreateCube()
ScaleEntity crates(i),0.5,0.5,0.5
crate_bodies(i)=CreatePhysicsBody(world,crates(i),PHYSICS_DYNAMIC)
crate_shape=PhysicsBodyBox(crate_bodies(i),1,1,1)
; Number each crate with a body tag
SetPhysicsBodyTag crate_bodies(i),i
Next
DropPile()
; Copy body movement and sleep events after every step
PhysicsBodyEvents world,True
; A yellow marker points at the crate the events pick out
marker=CreateCone(8)
ScaleEntity marker,0.3,0.4,0.3
RotateEntity marker,180,0,0
EntityColor marker,255,230,60
HideEntity marker
While Not KeyDown(1)
; R drops the pile again
If KeyHit(19) Then DropPile()
StepPhysics world,1.0/60.0,4
; The event keeps the tag the body had when the event happened
For e=1 To CountPhysicsBodyEvents(world)
If PhysicsBodyEventFellAsleep(world,e)
news$="Crate "+PhysicsBodyEventTag(world,e)+" fell asleep"
sleeper_entity=PhysicsBodyEventEntity(world,e)
EndIf
Next
If sleeper_entity
PositionEntity marker,EntityX(sleeper_entity),EntityY(sleeper_entity)+1.2,EntityZ(sleeper_entity)
ShowEntity marker
EndIf
; Orange crates are awake, grey crates are asleep
For i=1 To CRATE_COUNT
If PhysicsBodyIsAwake(crate_bodies(i))
EntityColor crates(i),255,120,70
Else
EntityColor crates(i),150,150,150
EndIf
Next
; 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: drop again Esc: exit"
Text 0,20,"PhysicsBodyEventTag: "+news
Flip
Wend
FreePhysicsWorld world
End
Function DropPile()
For i=1 To CRATE_COUNT
ResetPhysicsBody crate_bodies(i),Rnd(-1.5,1.5),2+i*0.8,Rnd(-1.5,1.5),0,Rnd(Pi),0
Next
End Function