From f91ff9e68b6332ce6ca1903fed4f7a17f6e5c80d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 1 Sep 2013 12:25:53 +0200 Subject: Added the cBoundingBox class. --- source/BoundingBox.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 source/BoundingBox.h (limited to 'source/BoundingBox.h') diff --git a/source/BoundingBox.h b/source/BoundingBox.h new file mode 100644 index 000000000..5a07df20e --- /dev/null +++ b/source/BoundingBox.h @@ -0,0 +1,67 @@ + +// BoundingBox.h + +// Declares the cBoundingBox class representing an axis-aligned bounding box with floatingpoint coords + + + + +#pragma once + +#include "Vector3d.h" + + + + + +// tolua_begin + +class cBoundingBox +{ +public: + cBoundingBox(double a_MinX, double a_MaxX, double a_MinY, double a_MaxY, double a_MinZ, double a_MaxZ); + cBoundingBox(const Vector3d & a_Min, const Vector3d & a_Max); + cBoundingBox(const Vector3d & a_Pos, double a_Radius, double a_Height); + cBoundingBox(const cBoundingBox & a_Orig); + + /// Moves the entire boundingbox by the specified offset + void Move(double a_OffX, double a_OffY, double a_OffZ); + + /// Moves the entire boundingbox by the specified offset + void Move(const Vector3d & a_Off); + + /// Expands the bounding box by the specified amount in each direction (so the box becomes larger by 2 * Expand in each direction) + void Expand(double a_ExpandX, double a_ExpandY, double a_ExpandZ); + + /// Returns true if the two bounding boxes intersect + bool DoesIntersect(const cBoundingBox & a_Other); + + /// Returns the union of the two bounding boxes + cBoundingBox Union(const cBoundingBox & a_Other); + + /// Returns true if the point is inside the bounding box + bool IsInside(const Vector3d & a_Point); + + /// Returns true if the point is inside the bounding box + bool IsInside(double a_X, double a_Y,double a_Z); + + /// Returns true if a_Other is inside this bounding box + bool IsInside(cBoundingBox & a_Other); + + /// Returns true if a boundingbox specified by a_Min and a_Max is inside this bounding box + bool IsInside(const Vector3d & a_Min, const Vector3d & a_Max); + + // tolua_end + + /// Calculates the intersection of the two bounding boxes; returns true if nonempty + bool Intersect(const cBoundingBox & a_Other, cBoundingBox & a_Intersection); + +protected: + Vector3d m_Min; + Vector3d m_Max; + +} ; // tolua_export + + + + -- cgit v1.2.3 From 5fccd67bada2be7a3fbb2df3abf08bfde58b600b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 1 Sep 2013 19:08:51 +0200 Subject: Added line collision calculation to cBoundingBox. --- source/BoundingBox.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source/BoundingBox.h') diff --git a/source/BoundingBox.h b/source/BoundingBox.h index 5a07df20e..7b6391942 100644 --- a/source/BoundingBox.h +++ b/source/BoundingBox.h @@ -51,6 +51,22 @@ public: /// Returns true if a boundingbox specified by a_Min and a_Max is inside this bounding box bool IsInside(const Vector3d & a_Min, const Vector3d & a_Max); + /// 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, const Vector3d & a_Point); + + /// 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); + + /** 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) + */ + bool CalcLineIntersection(const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face); + + /** 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) + */ + static bool CalcLineIntersection(const Vector3d & a_Min, const Vector3d & a_Max, const Vector3d & a_Line1, const Vector3d & a_Line2, double & a_LineCoeff, char & a_Face); + // tolua_end /// Calculates the intersection of the two bounding boxes; returns true if nonempty -- cgit v1.2.3 From 4f04724cfdbc4b6c7908423d0ad232a2ef374b1d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 1 Sep 2013 22:38:09 +0200 Subject: Made cBoundingBox class inclusive in both coord edges. Also added (a disabled) self-test to cBoundingBox. --- source/BoundingBox.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source/BoundingBox.h') diff --git a/source/BoundingBox.h b/source/BoundingBox.h index 7b6391942..cfaf6a318 100644 --- a/source/BoundingBox.h +++ b/source/BoundingBox.h @@ -16,6 +16,11 @@ // 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), +the boxes are considered non-intersecting. +*/ class cBoundingBox { public: -- cgit v1.2.3 From f5e0c8c77e66685f58a5013674c5f74a647d69a5 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 2 Sep 2013 19:51:13 +0200 Subject: cBoundingBox: Only forward collisions are calculated. --- source/BoundingBox.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/BoundingBox.h') diff --git a/source/BoundingBox.h b/source/BoundingBox.h index cfaf6a318..ff9963989 100644 --- a/source/BoundingBox.h +++ b/source/BoundingBox.h @@ -64,11 +64,13 @@ public: /** 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, char & a_Face); /** 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, char & a_Face); -- cgit v1.2.3