Fixed some stuff
This commit is contained in:
parent
c2d8e814a7
commit
d2d3c6c12f
2
init.lua
2
init.lua
@ -31,7 +31,7 @@ local current_folder = (...):gsub('%.init$', '') .. "."
|
||||
local cpml = {
|
||||
_LICENSE = "CPML is distributed under the terms of the MIT license. See LICENSE.md.",
|
||||
_URL = "https://github.com/shakesoda/cpml",
|
||||
_VERSION = "0.0.1",
|
||||
_VERSION = "0.0.9",
|
||||
_DESCRIPTION = "Cirno's Perfect Math Library: Just about everything you need for 3D games. Hopefully."
|
||||
}
|
||||
|
||||
|
@ -500,26 +500,29 @@ function quaternion.unit()
|
||||
end
|
||||
|
||||
-- http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||
function quaternion.lerp(a, b, dt)
|
||||
return a + dt * (b - a)
|
||||
end
|
||||
|
||||
-- http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||
function quaternion.nlerp(a, b, dt)
|
||||
return quaternion.lerp(a, b, dt):normalize()
|
||||
-- non-normalized rotations do not work out for quats!
|
||||
function quaternion.lerp(a, b, s)
|
||||
local v = a + (b - a) * s
|
||||
return v:normalize()
|
||||
end
|
||||
|
||||
-- http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
|
||||
function quaternion.slerp(a, b, dt)
|
||||
function quaternion.slerp(a, b, s)
|
||||
local function clamp(n, low, high) return math.min(math.max(n, low), high) end
|
||||
local dot = a:dot(b)
|
||||
|
||||
-- http://www.gamedev.net/topic/312067-shortest-slerp-path/#entry2995591
|
||||
if dot < 0 then
|
||||
a = -a
|
||||
dot = -dot
|
||||
end
|
||||
|
||||
if dot > constants.DOT_THRESHOLD then
|
||||
return quaternion.nlerp(a, b, dt)
|
||||
return quaternion.lerp(a, b, s)
|
||||
end
|
||||
|
||||
clamp(dot, -1, 1)
|
||||
local theta = math.acos(dot) * dt
|
||||
local theta = math.acos(dot) * s
|
||||
local c = (b - a * dot):normalize()
|
||||
|
||||
return a * math.cos(theta) + c * math.sin(theta)
|
||||
|
@ -233,6 +233,11 @@ function vector:orientation_to_direction(orientation)
|
||||
:rotated(self.x, new(1, 0, 0))
|
||||
end
|
||||
|
||||
-- http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||
function vector.lerp(a, b, s)
|
||||
return a + s * (b - a)
|
||||
end
|
||||
|
||||
-- the module
|
||||
return setmetatable({new = new, isvector = isvector, zero = zero},
|
||||
{__call = function(_, ...) return new(...) end})
|
||||
|
Loading…
x
Reference in New Issue
Block a user