summaryrefslogtreecommitdiffstats
path: root/src
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 /src
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--src/Bindings/ManualBindings.cpp80
-rw-r--r--src/BoundingBox.cpp4
-rw-r--r--src/BoundingBox.h25
3 files changed, 98 insertions, 11 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 91e80acbc..9945929d0 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -37,6 +37,7 @@
#include "../CommandOutput.h"
#include "../BuildInfo.h"
#include "../HTTP/UrlParser.h"
+#include "../BoundingBox.h"
@@ -3143,6 +3144,80 @@ static int tolua_cBlockArea_SaveToSchematicString(lua_State * tolua_S)
+static int tolua_cBoundingBox_CalcLineIntersection(lua_State * a_LuaState)
+{
+ /* Function signatures:
+ bbox:CalcLineIntersection(pt1, pt2) -> bool, [number, blockface]
+ cBoundingBox:CalcLineIntersection(min, max, pt1, pt2) -> bool, [number, blockface]
+ */
+ cLuaState L(a_LuaState);
+ const Vector3d * min;
+ const Vector3d * max;
+ const Vector3d * pt1;
+ const Vector3d * pt2;
+ double lineCoeff;
+ eBlockFace blockFace;
+ bool res;
+ if (L.GetStackValues(2, min, max, pt1, pt2)) // Try the static signature first
+ {
+ res = cBoundingBox::CalcLineIntersection(min, max, pt1, pt2, lineCoeff, blockFace);
+ }
+ else
+ {
+ const cBoundingBox * bbox;
+ if (!L.GetStackValues(1, bbox, pt1, pt2)) // Try the regular signature
+ {
+ L.LogStack();
+ tolua_error(a_LuaState, "Invalid function params. Expected either bbox:CalcLineIntersection(pt1, pt2) or cBoundingBox:CalcLineIntersection(min, max, pt1, pt2).", nullptr);
+ return 0;
+ }
+ res = bbox->CalcLineIntersection(pt1, pt2, lineCoeff, blockFace);
+ }
+ L.Push(res);
+ if (res)
+ {
+ L.Push(lineCoeff);
+ L.Push(blockFace);
+ return 3;
+ }
+ return 1;
+}
+
+
+
+
+
+static int tolua_cBoundingBox_Intersect(lua_State * a_LuaState)
+{
+ /* Function signature:
+ bbox:Intersect(a_OtherBbox) -> bool, cBoundingBox
+ */
+ cLuaState L(a_LuaState);
+ const cBoundingBox * self;
+ const cBoundingBox * other;
+ if (!L.GetStackValues(1, self, other))
+ {
+ L.LogStack();
+ tolua_error(a_LuaState, "Invalid function params. Expected bbox:Intersect(otherBbox).", nullptr);
+ return 0;
+ }
+ auto intersection = new cBoundingBox(*self);
+ auto res = self->Intersect(*other, *intersection);
+ L.Push(res);
+ if (!res)
+ {
+ delete intersection;
+ return 1;
+ }
+ L.Push(intersection);
+ tolua_register_gc(L, lua_gettop(L)); // Make Lua own the "intersection" object
+ return 2;
+}
+
+
+
+
+
static int tolua_cCompositeChat_AddRunCommandPart(lua_State * tolua_S)
{
// function cCompositeChat:AddRunCommandPart(Message, Command, [Style])
@@ -3431,6 +3506,11 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "SaveToSchematicString", tolua_cBlockArea_SaveToSchematicString);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cBoundingBox");
+ tolua_function(tolua_S, "CalcLineIntersection", tolua_cBoundingBox_CalcLineIntersection);
+ tolua_function(tolua_S, "Intersect", tolua_cBoundingBox_Intersect);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cClientHandle");
tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE);
tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE);
diff --git a/src/BoundingBox.cpp b/src/BoundingBox.cpp
index 8e3bb29a9..bd236bbd7 100644
--- a/src/BoundingBox.cpp
+++ b/src/BoundingBox.cpp
@@ -261,7 +261,7 @@ bool cBoundingBox::IsInside(const Vector3d & a_Min, const Vector3d & a_Max, doub
-bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face)
+bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face) const
{
return CalcLineIntersection(m_Min, m_Max, a_Line1, a_Line2, a_LineCoeff, a_Face);
}
@@ -336,7 +336,7 @@ bool cBoundingBox::CalcLineIntersection(const Vector3d & a_Min, const Vector3d &
-bool cBoundingBox::Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection)
+bool cBoundingBox::Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection) const
{
a_Intersection.m_Min.x = std::max(m_Min.x, a_Other.m_Min.x);
a_Intersection.m_Max.x = std::min(m_Max.x, a_Other.m_Max.x);
diff --git a/src/BoundingBox.h b/src/BoundingBox.h
index c2aa40dc7..38d567562 100644
--- a/src/BoundingBox.h
+++ b/src/BoundingBox.h
@@ -63,20 +63,25 @@ public:
/** Returns true if the specified point is inside the bounding box specified by its min / max corners */
static bool IsInside(const Vector3d & a_Min, const Vector3d & a_Max, double a_X, double a_Y, double a_Z);
+ // tolua_end
+
/** Returns true if this bounding box is intersected by the line specified by its two points
- Also calculates the distance along the line in which the intersection occurs (0 .. 1)
- Only forward collisions (a_LineCoeff >= 0) are returned. */
- bool CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face);
+ Also calculates the distance along the line in which the intersection occurs, and the face hit (BLOCK_FACE_ constants)
+ Only forward collisions (a_LineCoeff >= 0) are returned.
+ Exported to Lua manually, because ToLua++ would generate needless input params (a_LineCoeff, a_Face). */
+ bool CalcLineIntersection(const Vector3d & a_LinePoint1, const Vector3d & a_LinePoint2, double & a_LineCoeff, eBlockFace & a_Face) const;
/** Returns true if the specified bounding box is intersected by the line specified by its two points
- Also calculates the distance along the line in which the intersection occurs (0 .. 1) and the face hit (BLOCK_FACE_ constants)
- Only forward collisions (a_LineCoeff >= 0) are returned. */
- static bool CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, eBlockFace & a_Face);
+ Also calculates the distance along the line in which the intersection occurs, and the face hit (BLOCK_FACE_ constants)
+ Only forward collisions (a_LineCoeff >= 0) are returned.
+ Exported to Lua manually, because ToLua++ would generate needless input params (a_LineCoeff, a_Face). */
+ static bool CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_LinePoint1, const Vector3d & a_LinePoint2, double & a_LineCoeff, eBlockFace & a_Face);
- // tolua_end
+ /** Calculates the intersection of the two bounding boxes; returns true if nonempty.
+ Exported manually, because ToLua++ would generate needless input params (a_Intersection). */
+ bool Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection) const;
- /** Calculates the intersection of the two bounding boxes; returns true if nonempty */
- bool Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection);
+ // tolua_begin
double GetMinX(void) const { return m_Min.x; }
double GetMinY(void) const { return m_Min.y; }
@@ -89,6 +94,8 @@ public:
const Vector3d & GetMin(void) const { return m_Min; }
const Vector3d & GetMax(void) const { return m_Max; }
+ // tolua_end
+
protected:
Vector3d m_Min;
Vector3d m_Max;