Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IceOBB.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICEOBB_H__
13 #define __ICEOBB_H__
14 
15  // Forward declarations
16  class LSS;
17 
19  {
20  public:
22  inline_ OBB() {}
24  inline_ OBB(const Point& center, const Point& extents, const Matrix3x3& rot) : mCenter(center), mExtents(extents), mRot(rot) {}
27 
29 
32  void SetEmpty()
34  {
35  mCenter.Zero();
36  mExtents.Set(MIN_FLOAT, MIN_FLOAT, MIN_FLOAT);
37  mRot.Identity();
38  }
39 
41 
46  bool ContainsPoint(const Point& p) const;
48 
50 
55  void Create(const AABB& aabb, const Matrix4x4& mat);
57 
59 
64  inline_ void Rotate(const Matrix4x4& mtx, OBB& obb) const
66  {
67  // The extents remain constant
68  obb.mExtents = mExtents;
69  // The center gets x-formed
70  obb.mCenter = mCenter * mtx;
71  // Combine rotations
72  obb.mRot = mRot * Matrix3x3(mtx);
73  }
74 
76 
80  inline_ BOOL IsValid() const
82  {
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;
87  return TRUE;
88  }
89 
91 
96  bool ComputePlanes(Plane* planes) const;
98 
100 
105  bool ComputePoints(Point* pts) const;
107 
109 
114  bool ComputeVertexNormals(Point* pts) const;
116 
118 
122  const udword* GetEdges() const;
124 
126 
130  const Point* GetLocalEdgeNormals() const;
132 
134 
139  void ComputeWorldEdgeNormal(udword edge_index, Point& world_normal) const;
141 
143 
147  void ComputeLSS(LSS& lss) const;
149 
151 
156  bool IsInside(const OBB& box) const;
158 
159  inline_ const Point& GetCenter() const { return mCenter; }
160  inline_ const Point& GetExtents() const { return mExtents; }
161  inline_ const Matrix3x3& GetRot() const { return mRot; }
162 
163  inline_ void GetRotatedExtents(Matrix3x3& extents) const
164  {
165  extents = mRot;
166  extents.Scale(mExtents);
167  }
168 
172 
173  // Orientation is stored in row-major format,
174  // i.e. rows = eigen vectors of the covariance matrix
175  };
176 
177 #endif // __ICEOBB_H__