blob: d2fad5914ad88ad7d016b8e51d7f09e0731970ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
local prevx, prevy
return function(entities, id, data)
if not prevx then
prevx, prevy = data.xpos, data.ypos
end
local dx = data.xpos - prevx
local dy = data.ypos - prevy
prevx, prevy = data.xpos, data.ypos
local node = entities:getComponent(id, "node")
local py = entities:getComponent(id, "pitchyaw")
py.pitch = py.pitch - dy
py.yaw = py.yaw - dx
if py.pitch > 89.9 then py.pitch = 89.9 end
if py.pitch < -89.9 then py.pitch = -89.9 end
node.matrix
:identity()
:rotateY(math.rad(py.yaw))
:rotateX(math.rad(py.pitch))
end
|