diff --git a/modules/constants.lua b/modules/constants.lua index b485c3c..9b9dab0 100644 --- a/modules/constants.lua +++ b/modules/constants.lua @@ -1,3 +1,4 @@ +--- Various useful constants -- @module constants --- Constants diff --git a/modules/intersect.lua b/modules/intersect.lua index d3f0bdf..1af6f45 100644 --- a/modules/intersect.lua +++ b/modules/intersect.lua @@ -138,7 +138,7 @@ function intersect.ray_triangle(ray, triangle) -- return position of intersection if t >= DBL_EPSILON then local out = vec3() - out:mul(ray.direction, t) + out:scale(ray.direction, t) out:add(ray.position, out) return out @@ -177,7 +177,7 @@ function intersect.ray_sphere(ray, sphere) t = t < 0 and 0 or t local out = vec3() - out:mul(ray.direction, t) + out:scale(ray.direction, t) out:add(out, ray.position) -- Return collision point and distance from ray origin @@ -216,7 +216,7 @@ function intersect.ray_aabb(ray, aabb) end local out = vec3() - out:mul(ray.direction, tmin) + out:scale(ray.direction, tmin) out:add(out, ray.position) -- Return collision point and distance from ray origin @@ -245,7 +245,7 @@ function intersect.ray_plane(ray, plane) end local out = vec3() - out:mul(ray.direction, t) + out:scale(ray.direction, t) out:add(out, ray.position) -- Return collision point and distance from ray origin @@ -288,11 +288,11 @@ function intersect.line_line(a, b, e) -- return positions of intersection on each line local out1 = vec3() - out1:mul(p21, mua) + out1:scale(p21, mua) out1:add(out1, a[1]) local out2 = vec3() - out2:mul(p43, mub) + out2:scale(p43, mub) out2:add(out2, b[1]) local dist = out1:dist(out2) diff --git a/modules/octree.lua b/modules/octree.lua index 268c85c..ced1808 100644 --- a/modules/octree.lua +++ b/modules/octree.lua @@ -23,7 +23,7 @@ OctreeNode.__index = OctreeNode -- @param initialWorldSize Size of the sides of the initial node, in metres. The octree will never shrink smaller than this -- @param initialWorldPos Position of the centre of the initial node -- @param minNodeSize Nodes will stop splitting if the new nodes would be smaller than this (metres) --- @param loosenessVal Clamped between 1 and 2. Values > 1 let nodes overlap +-- @param looseness Clamped between 1 and 2. Values > 1 let nodes overlap local function new(initialWorldSize, initialWorldPos, minNodeSize, looseness) local tree = setmetatable({}, Octree) @@ -354,6 +354,7 @@ end -- @param ray Ray with a position and a direction -- @param func Function to execute on any objects within child nodes -- @param out Table to store results of func in +-- @param depth (used internally) -- @return boolean True if an intersect is detected function OctreeNode:cast_ray(ray, func, out, depth) depth = depth or 1 @@ -597,6 +598,7 @@ 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) diff --git a/modules/vec2.lua b/modules/vec2.lua index b9ce3fe..a323ca1 100644 --- a/modules/vec2.lua +++ b/modules/vec2.lua @@ -143,7 +143,7 @@ end function vec2.trim(out, a, len) return out :normalize(a) - :mul(out, math.min(a:len(), len)) + :scale(out, math.min(a:len(), len)) end --- Get the cross product of two vectors. @@ -267,7 +267,7 @@ end function vec2.lerp(out, a, b, s) return out :sub(b, a) - :mul(out, s) + :scale(out, s) :add(out, a) end diff --git a/spec/vec2_spec.lua b/spec/vec2_spec.lua index 1ab50c6..eb5c131 100644 --- a/spec/vec2_spec.lua +++ b/spec/vec2_spec.lua @@ -64,16 +64,16 @@ describe("vec2:", function() it("multiplies a vector by a scale factor", function() local a = vec2(3, 5) local s = 2 - local c = vec2():mul(a, s) + local c = vec2():scale(a, s) local d = a * s assert.is.equal(6, c.x) assert.is.equal(10, c.y) assert.is.equal(c, d) end) - it("divides a vector by a scale factor", function() + it("divides a vector by another vector", function() local a = vec2(3, 5) - local s = 2 + local s = vec2(2, 2) local c = vec2():div(a, s) local d = a / s assert.is.equal(1.5, c.x) diff --git a/spec/vec3_spec.lua b/spec/vec3_spec.lua index f032025..ced7825 100644 --- a/spec/vec3_spec.lua +++ b/spec/vec3_spec.lua @@ -71,7 +71,7 @@ describe("vec3:", function() it("multiplies a vector by a scale factor", function() local a = vec3(3, 5, 7) local s = 2 - local c = vec3():mul(a, s) + local c = vec3():scale(a, s) local d = a * s assert.is.equal(6, c.x) assert.is.equal(10, c.y) @@ -79,9 +79,9 @@ describe("vec3:", function() assert.is.equal(c, d) end) - it("divides a vector by a scale factor", function() + it("divides a vector by another vector", function() local a = vec3(3, 5, 7) - local s = 2 + local s = vec3(2, 2, 2) local c = vec3():div(a, s) local d = a / s assert.is.equal(1.5, c.x)