; 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