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_MATES_H 14 #define CHC_MATES_H 15 16 namespace chrono { 17 namespace collision { 18 19 /// Class for couple of 'overlapping' models, i.e. neighboring graph edge 20 /// (connecting two collision models). 21 /// Mostly used by broadphase colliders, for example like in 22 /// ChSweepAndPrune() engine. 23 24 template <class model_type> 25 class ChMates { 26 private: 27 model_type* m_A; 28 model_type* m_B; 29 30 public: 31 /// Axis overlap counter 32 /// (0=no overlaps, 1=partial overlap,only on an axis, 2=.., 3=full overlap on XYZ axes 33 short m_snp_axis_overlap_count; 34 35 /// Boolean flag indicating whether a overlap have been reported. 36 bool m_snp_overlap_reported; 37 38 /// Iterator to already-reported overlap. 39 typename std::list<ChMates<model_type>*>::iterator m_snp_reported_overlap; 40 41 /// Constructor. Arguments are the A and B models linked by this 42 /// graph edge of mates. 43 ChMates(model_type* mA = 0, model_type* mB = 0) m_A(mA)44 : m_A(mA), m_B(mB), m_snp_axis_overlap_count(0), m_snp_overlap_reported(false){}; 45 46 /// Return the hash key of this mates getHashkey(void)47 const unsigned int getHashkey(void) const { return ChMates::getHashkey(m_A, m_B); }; 48 49 /// Static function: return hash key for a generic mates item. getHashkey(model_type * A,model_type * B)50 static const unsigned int getHashkey(model_type* A, model_type* B) { 51 assert(A); 52 assert(B); 53 assert(A->GetBody()->GetIdentifier() != B->GetBody()->GetIdentifier()); 54 if (A->GetBody()->GetIdentifier() < B->GetBody()->GetIdentifier()) 55 return static_cast<unsigned int>( 56 ((A->GetBody()->GetIdentifier() << 16) | (B->GetBody()->GetIdentifier() & 0x0000FFFF))); 57 return static_cast<unsigned int>( 58 ((B->GetBody()->GetIdentifier() << 16) | (A->GetBody()->GetIdentifier() & 0x0000FFFF))); 59 }; 60 61 /// Returns the first collision model GetModelA()62 model_type* GetModelA() { return m_A; } 63 64 /// Returns the second collision model GetModelB()65 model_type* GetModelB() { return m_B; } 66 }; 67 68 } // end namespace collision 69 } // end namespace chrono 70 71 #endif 72