Blitz3D+ Command Reference

ProjectedZ# ( )

Parameters

None.

Description

Returns the viewport z coordinate produced by the most recent CameraProject call.

Its main job is validity checking: ProjectedZ is 0 when the projected point was behind the camera or beyond the camera's far range, and positive (the camera's near-plane distance) when the projection landed on screen. Test it before using ProjectedX/ProjectedY, otherwise markers for points behind the camera get drawn at mirrored positions.

See also: CameraProject, ProjectedX, ProjectedY.

Example

; ProjectedZ 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"
    ; ProjectedZ() tells you if the projected point lies in front of the camera
    Text 0,20,"ProjectedX: "+ProjectedX#()
    Text 0,40,"ProjectedY: "+ProjectedY#()
    Text 0,60,"ProjectedZ: "+ProjectedZ#()

    Flip

Wend

End

Index