00001 //## begin module%36FB166B02B2.cm preserve=no 00002 // %X% %Q% %Z% %W% 00003 //## end module%36FB166B02B2.cm 00004 00005 //## begin module%36FB166B02B2.cp preserve=no 00006 //## end module%36FB166B02B2.cp 00007 00008 //## Module: CD_Simple%36FB166B02B2; Pseudo Package body 00009 //## Source file: C:\project\mpk\code\CollisionDetectors\CD_Simple.cpp 00010 00011 //## begin module%36FB166B02B2.additionalIncludes preserve=no 00012 //## end module%36FB166B02B2.additionalIncludes 00013 00014 //## begin module%36FB166B02B2.includes preserve=yes 00015 //## end module%36FB166B02B2.includes 00016 00017 // CD_Simple 00018 #include "CollisionDetectors\CD_Simple.h" 00019 // Mesh 00020 #include "geometry\Mesh.h" 00021 //## begin module%36FB166B02B2.additionalDeclarations preserve=yes 00022 //## end module%36FB166B02B2.additionalDeclarations 00023 00024 00025 // Class CD_Simple 00026 00027 CD_Simple::CD_Simple (Universe& universe) 00028 //## begin CD_Simple::CD_Simple%922561219.hasinit preserve=no 00029 //## end CD_Simple::CD_Simple%922561219.hasinit 00030 //## begin CD_Simple::CD_Simple%922561219.initialization preserve=yes 00031 : 00032 CollisionDetectorBase( universe ), 00033 CD_BasicStyle( universe ), 00034 CD_Linear( universe ), 00035 CD_LinearContinuous( universe ) 00036 //## end CD_Simple::CD_Simple%922561219.initialization 00037 { 00038 //## begin CD_Simple::CD_Simple%922561219.body preserve=yes 00039 //create a new VCollide module for the mesh system 00040 Mesh::ResetVcollide() ; 00041 //## end CD_Simple::CD_Simple%922561219.body 00042 } 00043 00044 CD_Simple::CD_Simple (const CD_Simple& right) 00045 //## begin CD_Simple::CD_Simple%925235859.hasinit preserve=no 00046 //## end CD_Simple::CD_Simple%925235859.hasinit 00047 //## begin CD_Simple::CD_Simple%925235859.initialization preserve=yes 00048 : 00049 CollisionDetectorBase( right ), 00050 CD_BasicStyle( right ), 00051 CD_Linear( right ), 00052 CD_LinearContinuous( right ) 00053 //## end CD_Simple::CD_Simple%925235859.initialization 00054 { 00055 //## begin CD_Simple::CD_Simple%925235859.body preserve=yes 00056 // assert( false ) ; //IMPROVE: i'm not too sure that this function works 00057 Mesh::ResetVcollide() ; 00058 //## end CD_Simple::CD_Simple%925235859.body 00059 } 00060 00061 00062 CD_Simple::~CD_Simple() 00063 { 00064 //## begin CD_Simple::~CD_Simple%.body preserve=yes 00065 //## end CD_Simple::~CD_Simple%.body 00066 } 00067 00068 00069 00070 //## Other Operations (implementation) 00071 bool CD_Simple::IsInterfering (const Configuration& config) 00072 { 00073 //## begin CD_Simple::IsInterfering%923255749.body preserve=yes 00074 00075 //check all the entities against one another 00076 for( int i = 0; i < entities.size(); i++ ) 00077 { 00078 for( int j = i + 1 ; j < entities.size(); j++ ) 00079 { 00080 Entity* e1 = entities[ i ] ; 00081 Entity* e2 = entities[ j ] ; 00082 00083 //if the two entities are in the same base frame then intersection is impossible - implied CSG union 00084 int e1Base = e1->BaseFrame() ; 00085 int e2Base = e2->BaseFrame() ; 00086 bool shouldPerform = false ; 00087 shouldPerform |= this->ShouldPerformCollisionCheck( e1Base, e2Base ) ; 00088 shouldPerform |= this->ShouldPerformCollisionCheck( e2Base, e1Base ) ; 00089 if( !shouldPerform ) 00090 { 00091 continue ; 00092 } 00093 if( e1->BaseFrame() == e2->BaseFrame() ) 00094 { 00095 continue ; 00096 } 00097 if( abs( e1->BaseFrame() - e2->BaseFrame() ) == 1 ) 00098 { 00099 continue ; //IMPROVE:this skips out if the frames are adjacent - but it's a hack 00100 } 00101 //test e1 for interference with e2 00102 if( e1->CanCheckInterference( e2 ) ) 00103 { 00104 if( e1->IsInterfering( e2 ) ) 00105 { 00106 return true ; 00107 }; 00108 } 00109 else 00110 { 00111 //assert( e2->CanCheckInterference( e1 ) ); //IMPROVE: this assert needs to be here to verify that all collisions are taken care of 00112 if( e2->IsInterfering( e1 ) ) 00113 { 00114 return true ; 00115 } 00116 } 00117 } 00118 } 00119 00120 00121 return false ; 00122 //## end CD_Simple::IsInterfering%923255749.body 00123 } 00124 00125 CollisionDetectorBase* CD_Simple::Clone () const 00126 { 00127 //## begin CD_Simple::Clone%925235857.body preserve=yes 00128 CD_InterfaceToCollisionQueries* CDitc = dynamic_cast< CD_Bool* >( new CD_Simple( *this ) ) ; 00129 CollisionDetectorBase* returnMe = dynamic_cast< CollisionDetectorBase* >( CDitc ); 00130 return returnMe ; 00131 //## end CD_Simple::Clone%925235857.body 00132 } 00133 00134 // Additional Declarations 00135 //## begin CD_Simple%36FB166B02B2.declarations preserve=yes 00136 //## end CD_Simple%36FB166B02B2.declarations 00137 00138 //## begin module%36FB166B02B2.epilog preserve=yes 00139 //## end module%36FB166B02B2.epilog