now runs (with some require hax)
This commit is contained in:
parent
eb209f6d91
commit
4f3bb3ea5e
@ -1 +0,0 @@
|
||||
repo_token: WcsY9jsU97Zt0ZIbGHJftGkC8DsD16FVl
|
@ -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",
|
||||
}
|
||||
}
|
28
init.lua
28
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
|
||||
|
5
mod.conf
Normal file
5
mod.conf
Normal file
@ -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
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}, {
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -1,7 +1,6 @@
|
||||
--- Mesh utilities
|
||||
-- @module mesh
|
||||
|
||||
local modules = (...):gsub('%.[^%.]+$', '') .. "."
|
||||
local vec3 = require(modules .. "vec3")
|
||||
local mesh = {}
|
||||
|
||||
|
@ -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
|
||||
}, {
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user