SetMousePosition

This function will move the mouse to the specified position.

Syntax

Parameters

Example

freelookmode = true
camerarotation = Vec3()
--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)

model = Model:Box()
model:SetColor(0.0,0.0,1.0)

--Hide the mouse cursor
window:HideMouse()

--Move the mouse to the center of the screen
window:SetMousePosition(context:GetWidth()/2,context:GetHeight()/2)

while true do
if window:Closed() then return false end

--Press escape to end freelook mode
if (window:KeyHit(Key.Escape)) then

freelookmode=false
window:ShowMouse()
end

model:Turn(0,Time:GetSpeed(),0)

if (freelookmode) then

--Get the mouse movement
local sx = Math:Round(context:GetWidth()/2)
local sy = Math:Round(context:GetHeight()/2)
local mouseposition = window:GetMousePosition()
local dx = mouseposition.x - sx
local dy = mouseposition.y - sy

--Adjust and set the camera rotation
camerarotation.x = camerarotation.x + dy / 10.0
camerarotation.y = camerarotation.y + dx / 10.0
camera:SetRotation(camerarotation)

--Move the mouse to the center of the screen
window:SetMousePosition(sx,sy)
end

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

end