Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cHexahedron.h
Go to the documentation of this file.
1 //
5 
6 #ifndef _INC_cHexahedron_H
7 #define _INC_cHexahedron_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cBounds3.h"
13 #include "cPlane.h"
14 
15 namespace GrayLib
16 {
18  {
22  public:
23  typedef float DVALUE_t;
24  typedef UINT PLANES_MASK_t;
25  static const int k_NUMPLANES = 6;
26 
27  protected:
29  {
30  int m_Idx[6];
31  };
32  BBOX_INDICES_t m_BBoxIndices[k_NUMPLANES];
33  cPlanef m_aPlanes[k_NUMPLANES];
34 
35  public:
36  cHexahedron() noexcept
37  {}
38  cHexahedron(const cBounds3f& bbox);
39  // cHexahedron( const cVector3f& vEye, float fNearPlane, float fFarPlane, float fAngle );
40 
42  {
43  return (1 << k_NUMPLANES) - 1;
44  }
45 
46  void UpdateBBoxIndices();
47 
48  bool GetIntersection(const cBounds3f& box, OUT PLANES_MASK_t* planesMask = nullptr) const;
49  bool GetIntersection(const cSpheref& sphere, OUT PLANES_MASK_t* planesMask = nullptr) const;
50 
51  template<class TYPE> GINTERSECT_TYPE IntersectTest(const TYPE& obj) const
52  {
54  PLANES_MASK_t planesMask = get_FullPlanesMask();
55  if (!GetIntersection(obj, &planesMask))
56  {
57  return GINTERSECT_None;
58  }
59  if (planesMask != 0)
60  {
61  return GINTERSECT_Partial;
62  }
63  return GINTERSECT_In1; // 1 object is fully inside the other.
64  }
65 
68  {
71  for (int i = 0; i < k_NUMPLANES; i++)
72  m_aPlanes[i] = m_aPlanes[i].GetTransformPlane(m);
73  }
74 
76  {
78  for (int i = 0; i < k_NUMPLANES; i++)
79  m_aPlanes[i].TransformNormals(m);
80  }
81 
84  {
87  for (int i = 0; i < k_NUMPLANES; i++)
88  m_aPlanes[i].SetNormalized();
89  }
90 
91  void SetBounds(const cBounds3f& bbox);
92  void SetW(const cHexahedron& frustum, const cVector3f& vPos);
93  void SetFrustum(const cMatrix4x4f& m, DVALUE_t fUnit = 1);
94 
96  };
97 }
98 #endif
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define TYPE
Definition: StrT.cpp:38
Definition: cHexahedron.h:18
PLANES_MASK_t get_FullPlanesMask() const noexcept
Definition: cHexahedron.h:41
GINTERSECT_TYPE IntersectTest(const TYPE &obj) const
Definition: cHexahedron.h:51
UNITTEST_FRIEND(cHexahedron)
cHexahedron() noexcept
Definition: cHexahedron.h:36
void TransformCoords(const cMatrix4x4f &m)
to transform polyhedrons, multiply by transpose of inverse of actual transform
Definition: cHexahedron.h:67
void TransformNormals(const cMatrix4x4f &m)
Definition: cHexahedron.h:75
void SetNormalized()
set coords.
Definition: cHexahedron.h:83
UINT PLANES_MASK_t
Bit Mask of the 6 planes.
Definition: cHexahedron.h:24
float DVALUE_t
Dimension value type.
Definition: cHexahedron.h:23
Definition: cMatrix.h:194
Definition: cPlane.h:18
Definition: cSphere.h:20
Definition: cVector.h:94
Definition: cMesh.h:22
GINTERSECT_TYPE
Definition: cVecT.h:20
@ GINTERSECT_In1
object2 fully inside (or equal to) object1 (the main search comparator). CONTAINS
Definition: cVecT.h:28
@ GINTERSECT_Partial
object2 partly inside object1. partial intersection. INTERSECTS
Definition: cVecT.h:27
@ GINTERSECT_None
object2 completely outside object1 (no intersection) DISJOINT
Definition: cVecT.h:26
Definition: cHexahedron.h:29