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.2.0 $Rev: 2167 $
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  virtual void update();
121 
123  virtual bool computeCollision(cGenericObject* a_object,
124  cVector3d& a_segmentPointA,
125  cVector3d& a_segmentPointB,
126  cCollisionRecorder& a_recorder,
127  cCollisionSettings& a_settings);
128 
130  virtual void render(cRenderOptions& a_options);
131 
133  void initialize(const cGenericArrayPtr a_elements,
134  const double a_radius = 0.0);
135 
136 
137  //--------------------------------------------------------------------------
138  // PROTECTED METHODS:
139  //--------------------------------------------------------------------------
140 
141 protected:
142 
143  // This method is used to recursively build the collision tree.
144  int buildTree(const int a_indexFirstNode, const int a_indexLastNode, const int a_depth);
145 
146 
147  //--------------------------------------------------------------------------
148  // PROTECTED MEMBERS:
149  //--------------------------------------------------------------------------
150 
151 protected:
152 
154  double m_radius;
155 
158 
161 
163  std::vector<cCollisionAABBNode> m_nodes;
164 
167 
170 };
171 
172 //------------------------------------------------------------------------------
173 } // namespace chai3d
174 //------------------------------------------------------------------------------
175 
176 //------------------------------------------------------------------------------
177 #endif
178 //------------------------------------------------------------------------------
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:157
void initialize(const cGenericArrayPtr a_elements, const double a_radius=0.0)
This method initializes and builds the AABB collision tree.
Definition: CCollisionAABB.cpp:111
int buildTree(const int a_indexFirstNode, const int a_indexLastNode, const int a_depth)
Definition: CCollisionAABB.cpp:262
cGenericArrayPtr m_elements
Pointer to the list of elements in the object.
Definition: CCollisionAABB.h:160
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
virtual void render(cRenderOptions &a_options)
This method renders a visual representation of the collision tree.
Definition: CCollisionAABB.cpp:543
virtual 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:393
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:169
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:154
virtual void update()
This methods updates the collision detector and should be called if the 3D model it represents is mod...
Definition: CCollisionAABB.cpp:246
Implements an axis-aligned bounding box collision tree (AABB)
std::vector< cCollisionAABBNode > m_nodes
List of nodes.
Definition: CCollisionAABB.h:163
int m_rootIndex
Index number of root node.
Definition: CCollisionAABB.h:166
Definition: CAudioBuffer.cpp:56
std::shared_ptr< cGenericArray > cGenericArrayPtr
Definition: CGenericArray.h:70
virtual ~cCollisionAABB()
Destructor of cCollisionAABB.
Definition: CCollisionAABB.cpp:89