|
entity - entity handle camera - camera handle |
|
Returns true if the specified entity is inside the viewing area (frustum) of the specified camera. If the entity is a mesh, its bounding box is checked against the camera's frustum; for all other entity types only the centre position is checked. It answers 'would this be on screen?', which is not the same as 'can the player see it?' - the check ignores walls and other entities in the way. Combine it with EntityVisible for a full 'is it visibly on screen?' test. Typical uses: skipping expensive AI or effects for things off screen, deciding when to spawn enemies out of sight, or triggering a 'spotted!' event only when a target is actually in frame. See also: EntityVisible, CameraProject, CameraRange, CameraZoom. |
; EntityInView Example
; --------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,2,-10
light=CreateLight()
RotateEntity light,45,45,0
; Textured ground plane
plane=CreatePlane()
ground_tex=LoadTexture("media/MossyGround.BMP")
ScaleTexture ground_tex,4,4
EntityTexture plane,ground_tex
; A patrol drone flies left and right, crossing the edges of the camera's view
drone=CreateSphere()
PositionEntity drone,0,2,5
angle#=0
While Not KeyDown(1)
; Patrol far beyond both screen edges
angle=angle+1
PositionEntity drone,Sin(angle)*20,2,5
; 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
; Ask the camera whether the drone is inside its view frustum
in_view=EntityInView(drone,camera)
; Green while visible, red while outside the view (seen as it re-enters)
If in_view Then EntityColor drone,50,255,50 Else EntityColor drone,255,50,50
RenderWorld
Text 0,0,"Arrow keys: move camera Esc: exit"
If in_view Then
Text 0,20,"EntityInView(drone,camera) = 1 - the drone is on screen"
Else
Text 0,20,"EntityInView(drone,camera) = 0 - the drone has left the view"
EndIf
Flip
Wend
End