ProjectedX# ( )
Parameters
| None. |
Description
|
Returns the viewport x coordinate produced by the most recent CameraProject call. Use it (with ProjectedY) as the 2D position for drawing labels, health bars or markers over 3D objects. Check ProjectedZ first: if it is 0 the projected point was behind the camera or out of range and the x value is meaningless. The coordinate is relative to the camera's viewport, which covers the whole screen for a default camera. See also: CameraProject, ProjectedY, ProjectedZ. |
Example
; ProjectedX 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 drone that circles the scene - we will pin a HUD tag on it drone=CreateSphere() EntityColor drone,100,200,255 angle#=0 While Not KeyDown(1) ; Fly the drone in a bobbing circle angle=angle+1 PositionEntity drone,Cos(angle)*6,2+Sin(angle*3),Sin(angle)*6 ; 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 ; Project the drone's 3D position into 2D screen coordinates CameraProject camera,EntityX(drone),EntityY(drone),EntityZ(drone) RenderWorld ; Draw a HUD tag at the projected screen position while the drone is on screen If EntityInView(drone,camera) Then Rect ProjectedX()-20,ProjectedY()-20,40,40,False Text ProjectedX()-16,ProjectedY()-36,"DRONE" EndIf Text 0,0,"Arrow keys: move camera Esc: exit" ; ProjectedX() returns the screen x coordinate of the last CameraProject Text 0,20,"ProjectedX: "+ProjectedX#() Text 0,40,"ProjectedY: "+ProjectedY#() Text 0,60,"ProjectedZ: "+ProjectedZ#() Flip Wend End
Index