UnProject

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

Syntax

Parameters

Returns

Returns a position in global space.

Example

--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

--UnProject mouse coordinates from screen space to world space and position the box there
local p = window:GetMousePosition()
p.z = 3 --distance in front of the camera to project to
p = camera:UnProject(p)
model:SetPosition(p)

Time:Update()
world:Update()
world:Render()
context:Sync()
end