-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.lua
36 lines (32 loc) · 1.18 KB
/
common.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
---------------------------------------------------------------------------
-- Math extentions
---------------------------------------------------------------------------
function math.lerp(from,to,alpha)
return from + (to-from) * alpha
end
function math.clamp(low,value,high)
return math.max(low,math.min(value,high))
end
function math.wrap(low,value,high)
while value > high do
value = value - (high-low)
end
while value < low do
value = value + (high-low)
end
return value
end
function math.wrapdifference(low,value,other,high)
return math.wrap(low,value-other,high)+other
end
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Camera
---------------------------------------------------------------------------
function getCameraRot()
local px, py, pz, lx, ly, lz = getCameraMatrix()
local rotz = math.atan2 ( ( lx - px ), ( ly - py ) )
local rotx = math.atan2 ( lz - pz, getDistanceBetweenPoints2D ( lx, ly, px, py ) )
return math.deg(rotx), 180, -math.deg(rotz)
end
---------------------------------------------------------------------------