Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions [gameplay]/superman/vectors/CVectors.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
function newVector3D(posX, posY, posZ)
local newVector = {x = posX or 0.0, y = posY or 0.0, z = posZ or 0.0}

return newVector
end

function moduleVector3D(vector3D)
if not vector3D or type(vector3D.x) ~= "number" then
return 0
end
return math.sqrt(vector3D.x * vector3D.x + vector3D.y * vector3D.y + vector3D.z * vector3D.z)
end

function normalizeVector3D(vector3D)
if not vector3D or type(vector3D.x) ~= "number" then
return newVector3D(0, 0, 0)
end
local mod = moduleVector3D(vector3D)

if mod ~= 0 then
vector3D.x = vector3D.x / mod
vector3D.y = vector3D.y / mod
vector3D.z = vector3D.z / mod
end

return vector3D
end

function mulVector3D(vector3D, n)
if not vector3D or type(vector3D.x) ~= "number" or type(n) ~= "number" then
return newVector3D(0, 0, 0)
end
return newVector3D(vector3D.x * n, vector3D.y * n, vector3D.z * n)
end
end