Project

This function transforms a position in global space onto a position in screen space.

Syntax

Parameters

Returns

Returns a position in screen space. The X and Y components correspond to 2D screen coordinates, while the Z component contains the foreward distance to the projected point.

Example

pickradius = 0.5

--Create a window
window = Window:Create()
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
camera:Move(0,0,-3)
local light = DirectionalLight:Create()
light:SetRotation(35,35,0)

--Create a model
model = Model:Box()
model:SetColor(0.0,0.0,1.0)
model:SetRotation(0,-90,0)

while true do
if window:Closed() or window:KeyHit(Key.Escape) then return false end

--Make the model move in a circle
model:Turn(0,Time:GetSpeed()*0.5,0)
model:Move(0,0,0.1)

Time:Update()
world:Update()
world:Render()

local p = camera:Project(model:GetPosition())

local text = "This is a box!"
local font = context:GetFont()
p.x = p.x - font:GetTextWidth(text)/2
p.y = p.y - font:GetHeight()/2

context:SetBlendMode(Blend.Alpha)
context:DrawText(text,p.x,p.y)
context:Sync()
end