/
AxisAngleUtils.lua
53 lines (43 loc) · 1.16 KB
/
AxisAngleUtils.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
--[=[
Utility functions for axis angles.
@class AxisAngleUtils
]=]
local AxisAngleUtils = {}
--[=[
Converts an AxisAngle and position to a CFrame
@param axisAngle Vector3
@param position Vector3
@return CFrame
]=]
function AxisAngleUtils.toCFrame(axisAngle, position)
local angle = axisAngle.Magnitude
local cframe = CFrame.fromAxisAngle(axisAngle, angle)
if cframe ~= cframe then
-- warn("[AxisAngleUtils.toCFrame] - cframe is NAN")
if position then
return CFrame.new(position)
else
return CFrame.new()
end
end
if position then
cframe = cframe + position
end
return cframe
end
--[=[
Converts a CFrame to an AxisAngle and position
@param cframe CFrame
@return Vector3 -- AxisAngle
@return Vector3 -- position
]=]
function AxisAngleUtils.fromCFrame(cframe)
local axis, angle = cframe:ToAxisAngle()
local axisAngle = angle*axis
if axisAngle ~= axisAngle then
-- warn("[AxisAngleUtils.fromCFrame] - axisAngle is NAN")
return Vector3.zero, cframe.Position
end
return axisAngle, cframe.Position
end
return AxisAngleUtils