add rotated method to vector3
This commit is contained in:
parent
c9ac220089
commit
de9ee09074
@ -164,6 +164,22 @@ function Vector3:cross(with)
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
function Vector3:rotated(axis, angle)
|
||||
if not is_weak_vector3(axis) then
|
||||
error("Vector3: axis must be a Vector3-like table. Returning Vector3()")
|
||||
return Vector3()
|
||||
end
|
||||
|
||||
axis = Vector3(axis):normalized()
|
||||
local cosa = math.cos(angle)
|
||||
local sina = math.sin(angle)
|
||||
-- __mul is only defined for the left operand (table), numbers don't get metatables.
|
||||
-- as such, the ordering of operations here is specific
|
||||
local v = (self * cosa) + (axis * ((1 - cosa) * self:dot(axis))) + (axis:cross(self) * sina)
|
||||
return v
|
||||
end
|
||||
|
||||
---- CONSTANTS
|
||||
|
||||
Vector3.UP = Vector3(0, 1, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user