summaryrefslogtreecommitdiffstats
path: root/Server
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-06-05 18:23:16 +0200
committerMattes D <github@xoft.cz>2016-06-05 18:23:16 +0200
commitc2759186c09dc981aa672fecb57cce4aea722ec6 (patch)
treeece066d1c1f8e5ebe4a0da9cf918e06094002188 /Server
parentBindings: Add a const-ptr variant to all stack getter functions (diff)
downloadcuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.tar
cuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.tar.gz
cuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.tar.bz2
cuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.tar.lz
cuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.tar.xz
cuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.tar.zst
cuberite-c2759186c09dc981aa672fecb57cce4aea722ec6.zip
Diffstat (limited to '')
-rw-r--r--Server/Plugins/APIDump/Classes/Geometry.lua15
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua46
-rw-r--r--Server/Plugins/Debuggers/Info.lua6
3 files changed, 66 insertions, 1 deletions
diff --git a/Server/Plugins/APIDump/Classes/Geometry.lua b/Server/Plugins/APIDump/Classes/Geometry.lua
index 36bd222a6..8f2f76849 100644
--- a/Server/Plugins/APIDump/Classes/Geometry.lua
+++ b/Server/Plugins/APIDump/Classes/Geometry.lua
@@ -29,9 +29,22 @@ return
{ Params = "{{Vector3d|Pos}}, Radius, Height", Return = "cBoundingBox", Notes = "Creates a new bounding box from the position given and radius (X/Z) and height. Radius is added from X/Z to calculate the maximum coords and subtracted from X/Z to get the minimum; minimum Y is set to Pos.y and maxumim Y to Pos.y plus Height. This corresponds with how {{cEntity|entities}} are represented in Minecraft." },
{ Params = "OtherBoundingBox", Return = "cBoundingBox", Notes = "Creates a new copy of the given bounding box. Same result can be achieved by using a simple assignment." },
},
- CalcLineIntersection = { Params = "{{Vector3d|LineStart}}, {{Vector3d|LinePt2}}", Return = "DoesIntersect, LineCoeff, Face", Notes = "Calculates the intersection of a ray (half-line), given by two of its points, with the bounding box. Returns false if the line doesn't intersect the bounding box, or true, together with coefficient of the intersection (how much of the difference between the two ray points is needed to reach the intersection), and the face of the box which is intersected.<br /><b>TODO</b>: Lua binding for this function is wrong atm." },
+ CalcLineIntersection =
+ {
+ { Params = "{{Vector3d|LineStart}}, {{Vector3d|LinePt2}}", Return = "DoesIntersect, [LineCoeff, Face]", Notes = "Calculates the intersection of a ray (half-line), given by two of its points, with the bounding box. Returns false if the line doesn't intersect the bounding box, or true, together with coefficient of the intersection (how much of the difference between the two ray points is needed to reach the intersection), and the face of the box which is intersected." },
+ { Params = "{{Vector3d|BoxMin}}, {{Vector3d|BoxMax}}, {{Vector3d|LineStart}}, {{Vector3d|LinePt2}}", Return = "DoesIntersect, [LineCoeff, Face]", Notes = "(STATIC) Calculates the intersection of a ray (half-line), given by two of its points, with the bounding box specified as its minimum and maximum coords. Returns false if the line doesn't intersect the bounding box, or true, together with coefficient of the intersection (how much of the difference between the two ray points is needed to reach the intersection), and the face of the box which is intersected." },
+ },
DoesIntersect = { Params = "OtherBoundingBox", Return = "bool", Notes = "Returns true if the two bounding boxes have an intersection of nonzero volume." },
Expand = { Params = "ExpandX, ExpandY, ExpandZ", Return = "", Notes = "Expands this bounding box by the specified amount in each direction (so the box becomes larger by 2 * Expand in each axis)." },
+ GetMax = { Params = "", Return = "{{Vector3d|Point}}", Notes = "Returns the boundary point with the maximum coords" },
+ GetMaxX = { Params = "", Return = "number", Notes = "Returns the maximum X coord of the bounding box" },
+ GetMaxY = { Params = "", Return = "number", Notes = "Returns the maximum Y coord of the bounding box" },
+ GetMaxZ = { Params = "", Return = "number", Notes = "Returns the maximum Z coord of the bounding box" },
+ GetMin = { Params = "", Return = "{{Vector3d|Point}}", Notes = "Returns the boundary point with the minimum coords" },
+ GetMinX = { Params = "", Return = "number", Notes = "Returns the minimum X coord of the bounding box" },
+ GetMinY = { Params = "", Return = "number", Notes = "Returns the minimum Y coord of the bounding box" },
+ GetMinZ = { Params = "", Return = "number", Notes = "Returns the minimum Z coord of the bounding box" },
+ Intersect = { Params = "{{cBoundingBox|OtherBbox}}", Return = "bool, [{{cBoundingBox|bbox}}]", Notes = "Checks if the intersection between this bounding box and another one is non-empty. Returns false if the intersection is empty, true and a new cBoundingBox representing the intersection of the two boxes." },
IsInside =
{
{ Params = "{{Vector3d|Point}}", Return = "bool", Notes = "Returns true if the specified point is inside (including on the edge) of the box." },
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua
index aa2205368..362dc4dd9 100644
--- a/Server/Plugins/Debuggers/Debuggers.lua
+++ b/Server/Plugins/Debuggers/Debuggers.lua
@@ -1921,6 +1921,52 @@ end
+function HandleConsoleTestBbox(a_Split, a_EntireCmd)
+ -- Test bbox intersection:
+ local bbox1 = cBoundingBox(0, 5, 0, 5, 0, 5)
+ local bbox2 = cBoundingBox(bbox1) -- Make a copy
+ bbox2:Move(20, 20, 20)
+ local bbox3 = cBoundingBox(bbox1) -- Make a copy
+ bbox3:Move(2, 2, 2)
+ local doesIntersect, intersection = bbox1:Intersect(bbox2)
+ LOG("Bbox 2 intersection: " .. tostring(doesIntersect))
+ LOG(" Intersection type: " .. type(intersection) .. " / " .. tolua.type(intersection))
+ if (intersection) then
+ LOG(" {" .. intersection:GetMinX() .. ", " .. intersection:GetMinY() .. ", " .. intersection:GetMinZ() .. "}")
+ LOG(" {" .. intersection:GetMaxX() .. ", " .. intersection:GetMaxY() .. ", " .. intersection:GetMaxZ() .. "}")
+ end
+ doesIntersect, intersection = bbox1:Intersect(bbox3)
+ LOG("Bbox 3 intersection: " .. tostring(doesIntersect))
+ LOG(" Intersection type: " .. type(intersection) .. " / " .. tolua.type(intersection))
+ if (intersection) then
+ LOG(" {" .. intersection:GetMinX() .. ", " .. intersection:GetMinY() .. ", " .. intersection:GetMinZ() .. "}")
+ LOG(" {" .. intersection:GetMaxX() .. ", " .. intersection:GetMaxY() .. ", " .. intersection:GetMaxZ() .. "}")
+ end
+
+ -- Test line intersection:
+ local lines =
+ {
+ { Vector3d(5, 0, 5), Vector3d(5, 1, 5) },
+ { Vector3d(0, 0, 0), Vector3d(0, 1, 0) },
+ }
+ for idx, line in ipairs(lines) do
+ local doesIntersect, coeff, face = bbox2:CalcLineIntersection(line[1], line[2])
+ LOG("Line " .. idx .. " intersection: " .. tostring(doesIntersect))
+ LOG(" Coeff: " .. tostring(coeff))
+ LOG(" Face: " .. tostring(face))
+ local doesIntersect2, coeff2, face2 = cBoundingBox:CalcLineIntersection(bbox2:GetMin(), bbox2:GetMax(), line[1], line[2])
+ assert(doesIntersect == doesIntersect2)
+ assert(coeff == coeff2)
+ assert(face == face2)
+ end
+
+ return true
+end
+
+
+
+
+
function HandleConsoleTestCall(a_Split, a_EntireCmd)
LOG("Testing inter-plugin calls")
LOG("Note: These will fail if the Core plugin is not enabled")
diff --git a/Server/Plugins/Debuggers/Info.lua b/Server/Plugins/Debuggers/Info.lua
index af3461342..8fd04d0ae 100644
--- a/Server/Plugins/Debuggers/Info.lua
+++ b/Server/Plugins/Debuggers/Info.lua
@@ -254,6 +254,12 @@ g_PluginInfo =
HelpString = "Tests the world scheduling",
},
+ ["testbbox"] =
+ {
+ Handler = HandleConsoleTestBbox,
+ HelpString = "Tests cBoundingBox API"
+ },
+
["testcall"] =
{
Handler = HandleConsoleTestCall,