1
0
cuberite-2a/src/BoundingBox.h

114 lines
4.6 KiB
C
Raw Normal View History

2013-09-01 06:25:53 -04:00
// BoundingBox.h
// Declares the cBoundingBox class representing an axis-aligned bounding box with floatingpoint coords
#pragma once
#include "Defines.h"
2013-09-01 06:25:53 -04:00
// tolua_begin
/** Represents two sets of coords, minimum and maximum for each direction.
All the coords within those limits (inclusive the edges) are considered "inside" the box.
For intersection purposes, though, if the intersection is "sharp" in any coord (i. e. zero volume),
2015-07-31 10:49:10 -04:00
the boxes are considered non-intersecting. */
2013-09-01 06:25:53 -04:00
class cBoundingBox
{
public:
cBoundingBox(double a_MinX, double a_MaxX, double a_MinY, double a_MaxY, double a_MinZ, double a_MaxZ);
cBoundingBox(Vector3d a_Min, Vector3d a_Max);
cBoundingBox(Vector3d a_Pos, double a_Radius, double a_Height);
2017-08-21 04:46:41 -04:00
/** Constructor that allows to define a bounding box given a center point (a_Pos), a horizontal radius (a_Radius),
a height starting from given center point (a_Height) and a vertical offset (a_VerticalOffset) to adjust the vertical starting point.
For example: cBoundingBox([0, 0, 0], 6, 6, -3) would create a bounding cube from (-3, -3, -3) to (3, 3, 3). */
cBoundingBox(Vector3d a_Pos, double a_Radius, double a_Height, double a_VerticalOffset);
cBoundingBox(Vector3d a_Pos, double a_CubeLength);
#ifdef TOLUA_EXPOSITION // tolua isn't aware of implicitly generated copy constructors
cBoundingBox(const cBoundingBox & a_Orig);
#endif
2015-07-31 10:49:10 -04:00
/** Moves the entire boundingbox by the specified offset */
2013-09-01 06:25:53 -04:00
void Move(double a_OffX, double a_OffY, double a_OffZ);
2015-07-31 10:49:10 -04:00
/** Moves the entire boundingbox by the specified offset */
void Move(Vector3d a_Off);
2015-07-31 10:49:10 -04:00
/** Expands the bounding box by the specified amount in each direction (so the box becomes larger by 2 * Expand in each direction) */
2013-09-01 06:25:53 -04:00
void Expand(double a_ExpandX, double a_ExpandY, double a_ExpandZ);
2015-07-31 10:49:10 -04:00
/** Returns true if the two bounding boxes intersect */
2013-09-01 06:25:53 -04:00
bool DoesIntersect(const cBoundingBox & a_Other);
2015-07-31 10:49:10 -04:00
/** Returns the union of the two bounding boxes */
2013-09-01 06:25:53 -04:00
cBoundingBox Union(const cBoundingBox & a_Other);
2015-07-31 10:49:10 -04:00
/** Returns true if the point is inside the bounding box */
bool IsInside(Vector3d a_Point);
2015-07-31 10:49:10 -04:00
/** Returns true if the point is inside the bounding box */
2014-07-19 08:53:41 -04:00
bool IsInside(double a_X, double a_Y, double a_Z);
2015-07-31 10:49:10 -04:00
/** Returns true if a_Other is inside this bounding box */
2013-09-01 06:25:53 -04:00
bool IsInside(cBoundingBox & a_Other);
2015-07-31 10:49:10 -04:00
/** Returns true if a boundingbox specified by a_Min and a_Max is inside this bounding box */
bool IsInside(Vector3d a_Min, Vector3d a_Max);
2015-07-31 10:49:10 -04:00
/** Returns true if the specified point is inside the bounding box specified by its min / max corners */
static bool IsInside(Vector3d a_Min, Vector3d a_Max, Vector3d a_Point);
2015-07-31 10:49:10 -04:00
/** Returns true if the specified point is inside the bounding box specified by its min / max corners */
static bool IsInside(Vector3d a_Min, Vector3d a_Max, double a_X, double a_Y, double a_Z);
2016-06-05 12:23:16 -04:00
// tolua_end
/** Returns true if this bounding box is intersected by the line specified by its two points
2016-06-05 12:23:16 -04:00
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(Vector3d a_LinePoint1, 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
2016-06-05 12:23:16 -04:00
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(Vector3d a_Min, Vector3d a_Max, Vector3d a_LinePoint1, Vector3d a_LinePoint2, double & a_LineCoeff, eBlockFace & a_Face);
2016-06-05 12:23:16 -04:00
/** 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;
2016-06-05 12:23:16 -04:00
// tolua_begin
2014-09-03 10:56:59 -04:00
double GetMinX(void) const { return m_Min.x; }
double GetMinY(void) const { return m_Min.y; }
double GetMinZ(void) const { return m_Min.z; }
double GetMaxX(void) const { return m_Max.x; }
double GetMaxY(void) const { return m_Max.y; }
double GetMaxZ(void) const { return m_Max.z; }
Vector3d GetMin(void) const { return m_Min; }
Vector3d GetMax(void) const { return m_Max; }
2016-06-05 12:23:16 -04:00
// tolua_end
2013-09-01 06:25:53 -04:00
protected:
Vector3d m_Min;
Vector3d m_Max;
2013-09-01 06:25:53 -04:00
} ; // tolua_export