diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 8c8f444..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: WcsY9jsU97Zt0ZIbGHJftGkC8DsD16FVl \ No newline at end of file diff --git a/cpml-scm-1.rockspec b/cpml-scm-1.rockspec deleted file mode 100644 index 0ad4055..0000000 --- a/cpml-scm-1.rockspec +++ /dev/null @@ -1,31 +0,0 @@ -package = "cpml" -version = "scm-1" -source = { - url = "git://github.com/excessive/cpml.git" -} -description = { - summary = "Cirno's Perfect Math Library", - detailed = "Various useful bits of game math. 3D line intersections, ray casting, vectors, matrices, quaternions, etc.", - homepage = "http://github.com/excessive/cpml.git", - license = "MIT" -} -dependencies = { - "lua ~> 5.1" -} -build = { - type = "builtin", - modules = { - ["cpml"] = "init.lua", - ["cpml.modules.color"] = "modules/color.lua", - ["cpml.modules.constants"] = "modules/constants.lua", - ["cpml.modules.intersect"] = "modules/intersect.lua", - ["cpml.modules.mat4"] = "modules/mat4.lua", - ["cpml.modules.mesh"] = "modules/mesh.lua", - ["cpml.modules.octree"] = "modules/octree.lua", - ["cpml.modules.quat"] = "modules/quat.lua", - ["cpml.modules.simplex"] = "modules/simplex.lua", - ["cpml.modules.utils"] = "modules/utils.lua", - ["cpml.modules.vec2"] = "modules/vec2.lua", - ["cpml.modules.vec3"] = "modules/vec3.lua", - } -} diff --git a/init.lua b/init.lua index 2858792..09e57c2 100644 --- a/init.lua +++ b/init.lua @@ -32,8 +32,6 @@ :@@@@@@@++;;;+#@@@@@@+` .;'+++++;. --]] -local modules = (...) and (...):gsub('%.init$', '') .. ".modules." or "" - local cpml = { _LICENSE = "CPML is distributed under the terms of the MIT license. See LICENSE.md.", _URL = "https://github.com/excessive/cpml", @@ -58,8 +56,30 @@ local files = { "bound3", } +modules = minetest.get_modpath("mtul_math_cpml").."/modules/" +local old_require = require + +local len = #modules + +local loaded_modules = {} +function require(path) + if loaded_modules[path] then return loaded_modules[path] end + print(" TEST \n\n\n") + local ending = string.gsub(path:sub(len+1), "%.", "/")..".lua" + --[[if ending[1] ~= "/" then + ending = "/"..ending + end]] + path = modules..ending + print(path) + loaded_modules[path] = dofile(path) + return loaded_modules[path] +end for _, file in ipairs(files) do cpml[file] = require(modules .. file) end - -return cpml +--this may not be a good idea, we'll see. +for i, v in pairs(cpml) do + mtul.math[i] = v +end +modules = nil +require = old_require diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..e449818 --- /dev/null +++ b/mod.conf @@ -0,0 +1,5 @@ +name = mtul_math_cpml +title = MTUL Cirnos Perfect Math Library +description = integrates CPML library from the Love framework community into Minetest +author = CPML creators, FatalError42O +depends = mtul_core \ No newline at end of file diff --git a/modules/bound2.lua b/modules/bound2.lua index 0aecde7..90f558d 100644 --- a/modules/bound2.lua +++ b/modules/bound2.lua @@ -1,7 +1,6 @@ --- A 2 component bounding box. -- @module bound2 -local modules = (...):gsub('%.[^%.]+$', '') .. "." local vec2 = require(modules .. "vec2") local bound2 = {} @@ -10,8 +9,8 @@ local bound2_mt = {} -- Private constructor. local function new(min, max) return setmetatable({ - min=min, -- min: vec2, minimum value for each component - max=max, -- max: vec2, maximum value for each component + min=min, -- min: vec2, minimum value for each component + max=max, -- max: vec2, maximum value for each component }, bound2_mt) end @@ -50,7 +49,7 @@ function bound2.clone(a) return new(a.min, a.max) end ---- Construct a bound covering one or two points +--- Construct a bound covering one or two points -- @tparam vec2 a Any vector -- @tparam vec2 b Any second vector (optional) -- @treturn vec2 Minimum bound containing the given points @@ -78,7 +77,7 @@ function bound2.extend_bound(a, b) return a:extend(b.min):extend(b.max) end ---- Get size of bounding box as a vector +--- Get size of bounding box as a vector -- @tparam bound2 a bound -- @treturn vec2 Vector spanning min to max points function bound2.size(a) diff --git a/modules/bound3.lua b/modules/bound3.lua index c5c9751..b7f93b5 100644 --- a/modules/bound3.lua +++ b/modules/bound3.lua @@ -1,7 +1,6 @@ --- A 3-component axis-aligned bounding box. -- @module bound3 -local modules = (...):gsub('%.[^%.]+$', '') .. "." local vec3 = require(modules .. "vec3") local bound3 = {} @@ -10,7 +9,7 @@ local bound3_mt = {} -- Private constructor. local function new(min, max) return setmetatable({ - min=min, -- min: vec3, minimum value for each component + min=min, -- min: vec3, minimum value for each component max=max -- max: vec3, maximum value for each component }, bound3_mt) end @@ -50,7 +49,7 @@ function bound3.clone(a) return new(a.min, a.max) end ---- Construct a bound covering one or two points +--- Construct a bound covering one or two points -- @tparam vec3 a Any vector -- @tparam vec3 b Any second vector (optional) -- @treturn vec3 Minimum bound containing the given points @@ -78,7 +77,7 @@ function bound3.extend_bound(a, b) return a:extend(b.min):extend(b.max) end ---- Get size of bounding box as a vector +--- Get size of bounding box as a vector -- @tparam bound3 a bound -- @treturn vec3 Vector spanning min to max points function bound3.size(a) diff --git a/modules/bvh.lua b/modules/bvh.lua index acac611..6a8bfd9 100644 --- a/modules/bvh.lua +++ b/modules/bvh.lua @@ -3,7 +3,6 @@ --- BVH Tree -- @module bvh -local modules = (...):gsub('%.[^%.]+$', '') .. "." local intersect = require(modules .. "intersect") local vec3 = require(modules .. "vec3") local EPSILON = 1e-6 @@ -491,59 +490,6 @@ function BVHNode.ngSphereRadius(extentsMin, extentsMax) return math.sqrt(math.max(extentsMinDistSqr, extentsMaxDistSqr)) end ---[[ - ---- Draws node boundaries visually for debugging. --- @param cube Cube model to draw --- @param depth Used for recurcive calls to self method -function OctreeNode:draw_bounds(cube, depth) - depth = depth or 0 - local tint = depth / 7 -- Will eventually get values > 1. Color rounds to 1 automatically - - love.graphics.setColor(tint * 255, 0, (1 - tint) * 255) - local m = mat4() - :translate(self.center) - :scale(vec3(self.adjLength, self.adjLength, self.adjLength)) - - love.graphics.updateMatrix("transform", m) - love.graphics.setWireframe(true) - love.graphics.draw(cube) - love.graphics.setWireframe(false) - - for _, child in ipairs(self.children) do - child:draw_bounds(cube, depth + 1) - end - - love.graphics.setColor(255, 255, 255) -end - ---- Draws the bounds of all objects in the tree visually for debugging. --- @param cube Cube model to draw --- @param filter a function returning true or false to determine visibility. -function OctreeNode:draw_objects(cube, filter) - local tint = self.baseLength / 20 - love.graphics.setColor(0, (1 - tint) * 255, tint * 255, 63) - - for _, object in ipairs(self.objects) do - if filter and filter(object.data) or not filter then - local m = mat4() - :translate(object.bounds.center) - :scale(object.bounds.size) - - love.graphics.updateMatrix("transform", m) - love.graphics.draw(cube) - end - end - - for _, child in ipairs(self.children) do - child:draw_objects(cube, filter) - end - - love.graphics.setColor(255, 255, 255) -end - ---]] - Node = setmetatable({ new = new_node }, { diff --git a/modules/color.lua b/modules/color.lua index e78e9e7..f0c1242 100644 --- a/modules/color.lua +++ b/modules/color.lua @@ -1,7 +1,6 @@ --- Color utilities -- @module color -local modules = (...):gsub('%.[^%.]+$', '') .. "." local constants = require(modules .. "constants") local utils = require(modules .. "utils") local precond = require(modules .. "_private_precond") diff --git a/modules/intersect.lua b/modules/intersect.lua index c8d7086..fbd845a 100644 --- a/modules/intersect.lua +++ b/modules/intersect.lua @@ -1,7 +1,6 @@ --- Various geometric intersections -- @module intersect -local modules = (...):gsub('%.[^%.]+$', '') .. "." local constants = require(modules .. "constants") local mat4 = require(modules .. "mat4") local vec3 = require(modules .. "vec3") diff --git a/modules/mat4.lua b/modules/mat4.lua index ef4f331..4018462 100644 --- a/modules/mat4.lua +++ b/modules/mat4.lua @@ -1,6 +1,5 @@ --- double 4x4, 1-based, column major matrices -- @module mat4 -local modules = (...):gsub('%.[^%.]+$', '') .. "." local constants = require(modules .. "constants") local vec2 = require(modules .. "vec2") local vec3 = require(modules .. "vec3") diff --git a/modules/mesh.lua b/modules/mesh.lua index 1d25ae7..963a6ff 100644 --- a/modules/mesh.lua +++ b/modules/mesh.lua @@ -1,7 +1,6 @@ --- Mesh utilities -- @module mesh -local modules = (...):gsub('%.[^%.]+$', '') .. "." local vec3 = require(modules .. "vec3") local mesh = {} diff --git a/modules/octree.lua b/modules/octree.lua index fbc15f1..cb72d72 100644 --- a/modules/octree.lua +++ b/modules/octree.lua @@ -6,7 +6,6 @@ --- Octree -- @module octree -local modules = (...):gsub('%.[^%.]+$', '') .. "." local intersect = require(modules .. "intersect") local mat4 = require(modules .. "mat4") local utils = require(modules .. "utils") @@ -572,55 +571,6 @@ function OctreeNode:has_any_objects() return false end ---- Draws node boundaries visually for debugging. --- @param cube Cube model to draw --- @param depth Used for recurcive calls to this method -function OctreeNode:draw_bounds(cube, depth) - depth = depth or 0 - local tint = depth / 7 -- Will eventually get values > 1. Color rounds to 1 automatically - - love.graphics.setColor(tint * 255, 0, (1 - tint) * 255) - local m = mat4() - :translate(self.center) - :scale(vec3(self.adjLength, self.adjLength, self.adjLength)) - - love.graphics.updateMatrix("transform", m) - love.graphics.setWireframe(true) - love.graphics.draw(cube) - love.graphics.setWireframe(false) - - for _, child in ipairs(self.children) do - child:draw_bounds(cube, depth + 1) - end - - love.graphics.setColor(255, 255, 255) -end - ---- Draws the bounds of all objects in the tree visually for debugging. --- @param cube Cube model to draw --- @param filter a function returning true or false to determine visibility. -function OctreeNode:draw_objects(cube, filter) - local tint = self.baseLength / 20 - love.graphics.setColor(0, (1 - tint) * 255, tint * 255, 63) - - for _, object in ipairs(self.objects) do - if filter and filter(object.data) or not filter then - local m = mat4() - :translate(object.bounds.center) - :scale(object.bounds.size) - - love.graphics.updateMatrix("transform", m) - love.graphics.draw(cube) - end - end - - for _, child in ipairs(self.children) do - child:draw_objects(cube, filter) - end - - love.graphics.setColor(255, 255, 255) -end - Node = setmetatable({ new = new_node }, { diff --git a/modules/quat.lua b/modules/quat.lua index 999f970..7187bfb 100644 --- a/modules/quat.lua +++ b/modules/quat.lua @@ -1,7 +1,6 @@ --- A quaternion and associated utilities. -- @module quat -local modules = (...):gsub('%.[^%.]+$', '') .. "." local constants = require(modules .. "constants") local vec3 = require(modules .. "vec3") local precond = require(modules .. "_private_precond") diff --git a/modules/utils.lua b/modules/utils.lua index 6b2ebb7..1296f12 100644 --- a/modules/utils.lua +++ b/modules/utils.lua @@ -1,7 +1,6 @@ --- Various utility functions -- @module utils -local modules = (...): gsub('%.[^%.]+$', '') .. "." local vec2 = require(modules .. "vec2") local vec3 = require(modules .. "vec3") local private = require(modules .. "_private_utils") diff --git a/modules/vec2.lua b/modules/vec2.lua index c392444..00ffdd5 100644 --- a/modules/vec2.lua +++ b/modules/vec2.lua @@ -1,7 +1,6 @@ --- A 2 component vector. -- @module vec2 -local modules = (...):gsub('%.[^%.]+$', '') .. "." local vec3 = require(modules .. "vec3") local precond = require(modules .. "_private_precond") local private = require(modules .. "_private_utils") diff --git a/modules/vec3.lua b/modules/vec3.lua index b653506..d634d22 100644 --- a/modules/vec3.lua +++ b/modules/vec3.lua @@ -1,7 +1,6 @@ --- A 3 component vector. -- @module vec3 -local modules = (...):gsub('%.[^%.]+$', '') .. "." local precond = require(modules .. "_private_precond") local private = require(modules .. "_private_utils") local sqrt = math.sqrt