CCollisionAABB.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Chris Sewell
40  \author Charity Lu
41  \author Francois Conti
42  \version 3.1.1 $Rev: 1869 $
43 */
44 //==============================================================================
45 
46 //------------------------------------------------------------------------------
47 #ifndef CCollisionAABBH
48 #define CCollisionAABBH
49 //------------------------------------------------------------------------------
50 #include "math/CMaths.h"
53 //------------------------------------------------------------------------------
54 #include <vector>
55 //------------------------------------------------------------------------------
56 
57 //------------------------------------------------------------------------------
58 namespace chai3d {
59 //------------------------------------------------------------------------------
60 
61 //==============================================================================
68 //==============================================================================
69 
70 //==============================================================================
83 //==============================================================================
85 {
86  enum cCollisionAABBState
87  {
88  C_AABB_STATE_TEST_CURRENT_NODE,
89  C_AABB_STATE_TEST_LEFT_NODE,
90  C_AABB_STATE_TEST_RIGHT_NODE,
91  C_AABB_STATE_POP_STACK
92  };
93 
94  struct cCollisionAABBStack
95  {
96  int m_index;
97  cCollisionAABBState m_state;
98  };
99 
100  //--------------------------------------------------------------------------
101  // CONSTRUCTOR & DESTRUCTOR:
102  //--------------------------------------------------------------------------
103 
104 public:
105 
107  cCollisionAABB();
108 
110  virtual ~cCollisionAABB();
111 
112 
113  //--------------------------------------------------------------------------
114  // PUBLIC METHODS:
115  //--------------------------------------------------------------------------
116 
117 public:
118 
120  void initialize(const cGenericArrayPtr a_elements,
121  const double a_radius = 0.0);
122 
124  void render(cRenderOptions& a_options);
125 
127  bool computeCollision(cGenericObject* a_object,
128  cVector3d& a_segmentPointA,
129  cVector3d& a_segmentPointB,
130  cCollisionRecorder& a_recorder,
131  cCollisionSettings& a_settings);
132 
133 
134  //--------------------------------------------------------------------------
135  // PROTECTED METHODS:
136  //--------------------------------------------------------------------------
137 
138 protected:
139 
140  // This method is used to recursively build the collision tree.
141  int buildTree(const int a_indexFirstNode, const int a_indexLastNode, const int a_depth);
142 
143 
144  //--------------------------------------------------------------------------
145  // PROTECTED MEMBERS:
146  //--------------------------------------------------------------------------
147 
148 protected:
149 
151  double m_radius;
152 
155 
158 
160  std::vector<cCollisionAABBNode> m_nodes;
161 
164 
167 };
168 
169 //------------------------------------------------------------------------------
170 } // namespace chai3d
171 //------------------------------------------------------------------------------
172 
173 //------------------------------------------------------------------------------
174 #endif
175 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
Implements general math utility functions.
int m_numElements
Number of elements inside tree.
Definition: CCollisionAABB.h:154
void initialize(const cGenericArrayPtr a_elements, const double a_radius=0.0)
This method initializes and builds the AABB collision tree.
Definition: CCollisionAABB.cpp:109
int buildTree(const int a_indexFirstNode, const int a_indexLastNode, const int a_depth)
Definition: CCollisionAABB.cpp:248
cGenericArrayPtr m_elements
Pointer to the list of elements in the object.
Definition: CCollisionAABB.h:157
This class implements an axis-aligned bounding box collision detector.
Definition: CCollisionAABB.h:84
This class implements a base class for collision detection.
Definition: CGenericCollision.h:101
void render(cRenderOptions &a_options)
This method renders a visual representation of the collision tree.
Definition: CCollisionAABB.cpp:529
bool computeCollision(cGenericObject *a_object, cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cCollisionRecorder &a_recorder, cCollisionSettings &a_settings)
This method computes all collisions between a segment passed as argument and the attributed 3D object...
Definition: CCollisionAABB.cpp:379
Implements a base class for programming collision detectors that identify intersections between segme...
This class implements a base class for all 2D or 3D objects in CHAI3D.
Definition: CGenericObject.h:112
cCollisionAABB()
Constructor of cCollisionAABB.
Definition: CCollisionAABB.cpp:63
This class implements a collision detection recorder that stores all collision events that are report...
Definition: CCollisionBasics.h:185
int m_maxDepth
Maximum depth of tree.
Definition: CCollisionAABB.h:166
This structure stores the collision settings that are passed to a collision detector when querying fo...
Definition: CCollisionBasics.h:242
double m_radius
Collision shell radius around elements.
Definition: CCollisionAABB.h:151
Implements an axis-aligned bounding box collision tree (AABB)
std::vector< cCollisionAABBNode > m_nodes
List of nodes.
Definition: CCollisionAABB.h:160
int m_rootIndex
Index number of root node.
Definition: CCollisionAABB.h:163
Definition: CAudioBuffer.cpp:56
std::shared_ptr< cGenericArray > cGenericArrayPtr
Definition: CGenericArray.h:70
virtual ~cCollisionAABB()
Destructor of cCollisionAABB.
Definition: CCollisionAABB.cpp:89