PhysicsSensorShape ( world,event_type,index )
Parameters
|
world - physics-world handle returned by CreatePhysicsWorld event_type - sensor list to read: 1 begin or 2 end index - 1-based position in that list, up to CountPhysicsSensorEvents |
Description
|
Returns the sensor shape from a sensor overlap event. This identifies which trigger volume fired - the shape that was created with the sensor flag. Its partner getter, PhysicsSensorVisitor, tells you what walked in or out. With several triggers in a level, compare this handle against your stored sensor shapes to know whether it was the checkpoint, the lava zone or the shop doorway. Sensor events 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: CountPhysicsSensorEvents, PhysicsSensorVisitor, PhysicsBodyBox, StepPhysics. |
Example
; PhysicsSensorShape Example ; -------------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() Const PHYSICS_STATIC=0 Const PHYSICS_KINEMATIC=1 Const PHYSICS_SENSOR_BEGIN=1 Const PHYSICS_SENSOR_END=2 camera=CreateCamera() PositionEntity camera,0,3,-4 light=CreateLight() RotateEntity light,45,-30,0 AmbientLight 50,50,50 world=CreatePhysicsWorld() PhysicsGravity world,0,0,0 ; A transparent trigger zone: the final 1 makes the box shape a sensor zone=CreateCube() ScaleEntity zone,1.5,1.5,1.5 PositionEntity zone,0,1,5,True EntityColor zone,80,160,255 EntityAlpha zone,0.35 zone_body=CreatePhysicsBody(world,zone,PHYSICS_STATIC) zone_shape=PhysicsBodyBox(zone_body,3,3,3,0,0,0,0,1) ; A kinematic patrol ball that flies back and forth through the zone ball=CreateSphere(16) ScaleEntity ball,0.5,0.5,0.5 PositionEntity ball,-5,1,5,True EntityColor ball,255,120,70 ball_body=CreatePhysicsBody(world,ball,PHYSICS_KINEMATIC) ball_shape=PhysicsBodySphere(ball_body,1,1) angle#=270 paused=0 inside=0 begin_count=0 While Not KeyDown(1) ; Space pauses or resumes the patrol If KeyHit(57) Then paused=1-paused If paused=0 Then angle=angle+1.2 PositionEntity ball,Sin(angle)*5,1,5,True StepPhysics world,1.0/60.0,4 ; Scan this step's sensor begin events For index=1 To CountPhysicsSensorEvents(world,PHYSICS_SENSOR_BEGIN) sensor_shape=PhysicsSensorShape(world,PHYSICS_SENSOR_BEGIN,index) visitor_shape=PhysicsSensorVisitor(world,PHYSICS_SENSOR_BEGIN,index) If sensor_shape=zone_shape And visitor_shape=ball_shape inside=1 begin_count=begin_count+1 EndIf Next ; And this step's sensor end events For index=1 To CountPhysicsSensorEvents(world,PHYSICS_SENSOR_END) sensor_shape=PhysicsSensorShape(world,PHYSICS_SENSOR_END,index) visitor_shape=PhysicsSensorVisitor(world,PHYSICS_SENSOR_END,index) If sensor_shape=zone_shape And visitor_shape=ball_shape Then inside=0 Next ; The zone lights up green while the ball is inside it If inside Then EntityColor zone,90,255,120 Else EntityColor zone,80,160,255 ; 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,"Space: pause the patrol Arrow keys: move camera Esc: exit" Text 0,20,"PhysicsSensorShape(world,1,1) = "+sensor_shape+" zone_shape = "+zone_shape Text 0,40,"Ball inside zone: "+inside+" Begin events so far: "+begin_count Flip Wend FreePhysicsWorld world End
Index