1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 13 #ifndef CHC_ABSOLUTEAABB_H 14 #define CHC_ABSOLUTEAABB_H 15 16 namespace chrono { 17 namespace collision { 18 19 /// Class for end point, to be used for X or Y or Z lists of 20 /// the 'sweep and prune' broad-phase collision. 21 22 template <class coll_model_type> 23 class ChIntervalEndpoint { 24 public: 25 /// Constructor ChIntervalEndpoint(void)26 ChIntervalEndpoint(void) : m_type(0), m_model(0){}; 27 28 /// Initialize init(coll_model_type * model,const unsigned int & type)29 void init(coll_model_type* model, const unsigned int& type) { 30 assert(model); 31 assert(type == 0 || type == 1); 32 this->m_model = model; 33 this->m_type = type; 34 }; 35 36 public: 37 double m_value; ///< scalar value of the endpoint. 38 coll_model_type* m_model; ///< pointer to the body. 39 unsigned int m_type; ///< start point=0; end point =1; 40 }; 41 42 /// Header for defining AABB (axis-aligned bounding 43 /// boxes) in absolute space, to be used with 44 /// the 'sweep and prune' broad-phase 45 /// collision detection stage. This AABB is made of eight 46 /// ChIntervalEndpoint() items. 47 48 template <class coll_model_type> 49 class ChAbsoluteAABB { 50 public: ChAbsoluteAABB(void)51 ChAbsoluteAABB(void) : m_model(0){}; 52 init(coll_model_type * amodel)53 void init(coll_model_type* amodel) { 54 if (!m_model) { 55 m_model = amodel; 56 m_beginX.init(amodel, 0); 57 m_beginY.init(amodel, 0); 58 m_beginZ.init(amodel, 0); 59 m_endX.init(amodel, 1); 60 m_endY.init(amodel, 1); 61 m_endZ.init(amodel, 1); 62 } 63 assert(m_model); 64 }; 65 66 public: 67 coll_model_type* m_model; ///< A pointer to the corresponding collision model this AABB encloses. 68 69 ChIntervalEndpoint<coll_model_type> m_beginX; 70 ChIntervalEndpoint<coll_model_type> m_beginY; 71 ChIntervalEndpoint<coll_model_type> m_beginZ; 72 ChIntervalEndpoint<coll_model_type> m_endX; 73 ChIntervalEndpoint<coll_model_type> m_endY; 74 ChIntervalEndpoint<coll_model_type> m_endZ; 75 }; 76 77 } // end namespace collision 78 } // end namespace chrono 79 80 #endif 81