1
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3
* Contains OBB-related code. (oriented bounding box)
5
* \author Pierre Terdiman
6
* \date January, 13, 2000
8
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
15
// Forward declarations
18
class ICEMATHS_API OBB
24
inline_ OBB(const Point& center, const Point& extents, const Matrix3x3& rot) : mCenter(center), mExtents(extents), mRot(rot) {}
28
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30
* Setups an empty OBB.
32
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36
mExtents.Set(MIN_FLOAT, MIN_FLOAT, MIN_FLOAT);
40
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42
* Tests if a point is contained within the OBB.
43
* \param p [in] the world point to test
44
* \return true if inside the OBB
46
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
47
bool ContainsPoint(const Point& p) const;
49
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51
* Builds an OBB from an AABB and a world transform.
52
* \param aabb [in] the aabb
53
* \param mat [in] the world transform
55
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56
void Create(const AABB& aabb, const Matrix4x4& mat);
58
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60
* Recomputes the OBB after an arbitrary transform by a 4x4 matrix.
61
* \param mtx [in] the transform matrix
62
* \param obb [out] the transformed OBB
64
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65
inline_ void Rotate(const Matrix4x4& mtx, OBB& obb) const
67
// The extents remain constant
68
obb.mExtents = mExtents;
69
// The center gets x-formed
70
obb.mCenter = mCenter * mtx;
72
obb.mRot = mRot * Matrix3x3(mtx);
75
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
* Checks the OBB is valid.
78
* \return true if the box is valid
80
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81
inline_ BOOL IsValid() const
83
// Consistency condition for (Center, Extents) boxes: Extents >= 0.0f
84
if(mExtents.x < 0.0f) return FALSE;
85
if(mExtents.y < 0.0f) return FALSE;
86
if(mExtents.z < 0.0f) return FALSE;
90
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
92
* Computes the obb planes.
93
* \param planes [out] 6 box planes
94
* \return true if success
96
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97
bool ComputePlanes(Plane* planes) const;
99
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
101
* Computes the obb points.
102
* \param pts [out] 8 box points
103
* \return true if success
105
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106
bool ComputePoints(Point* pts) const;
108
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
* Computes vertex normals.
111
* \param pts [out] 8 box points
112
* \return true if success
114
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115
bool ComputeVertexNormals(Point* pts) const;
117
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120
* \return 24 indices (12 edges) indexing the list returned by ComputePoints()
122
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123
const udword* GetEdges() const;
125
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
127
* Returns local edge normals.
128
* \return edge normals in local space
130
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131
const Point* GetLocalEdgeNormals() const;
133
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
135
* Returns world edge normal
136
* \param edge_index [in] 0 <= edge index < 12
137
* \param world_normal [out] edge normal in world space
139
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
140
void ComputeWorldEdgeNormal(udword edge_index, Point& world_normal) const;
142
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144
* Computes an LSS surrounding the OBB.
145
* \param lss [out] the LSS
147
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148
void ComputeLSS(LSS& lss) const;
150
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
152
* Checks the OBB is inside another OBB.
153
* \param box [in] the other OBB
154
* \return TRUE if we're inside the other box
156
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
157
BOOL IsInside(const OBB& box) const;
159
inline_ const Point& GetCenter() const { return mCenter; }
160
inline_ const Point& GetExtents() const { return mExtents; }
161
inline_ const Matrix3x3& GetRot() const { return mRot; }
163
inline_ void GetRotatedExtents(Matrix3x3& extents) const
166
extents.Scale(mExtents);
169
Point mCenter; //!< B for Box
170
Point mExtents; //!< B for Bounding
171
Matrix3x3 mRot; //!< O for Oriented
173
// Orientation is stored in row-major format,
174
// i.e. rows = eigen vectors of the covariance matrix
177
#endif // __ICEOBB_H__