basic/geometry/MPK_Sphere.cpp

Go to the documentation of this file.
00001 //## begin module%36FE7C01006E.cm preserve=no
00002 //        %X% %Q% %Z% %W%
00003 //## end module%36FE7C01006E.cm
00004 
00005 //## begin module%36FE7C01006E.cp preserve=no
00006 //## end module%36FE7C01006E.cp
00007 
00008 //## Module: MPK_Sphere%36FE7C01006E; Pseudo Package body
00009 //## Source file: C:\user\gipson\projects\mpk\code\geometry\MPK_Sphere.cpp
00010 
00011 //## begin module%36FE7C01006E.additionalIncludes preserve=no
00012 //## end module%36FE7C01006E.additionalIncludes
00013 
00014 //## begin module%36FE7C01006E.includes preserve=yes
00015 #include "geometry\MPK_Cylinder.h"
00016 //## end module%36FE7C01006E.includes
00017 
00018 // MPK_Sphere
00019 #include "geometry\MPK_Sphere.h"
00020 // FrameManager
00021 #include "Kinematics\FrameManager.h"
00022 //## begin module%36FE7C01006E.additionalDeclarations preserve=yes
00023 //## end module%36FE7C01006E.additionalDeclarations
00024 
00025 
00026 // Class MPK_Sphere 
00027 
00028 
00029 
00030 MPK_Sphere::MPK_Sphere (FrameManager* frameManager)
00031   //## begin MPK_Sphere::MPK_Sphere%922649214.hasinit preserve=no
00032   //## end MPK_Sphere::MPK_Sphere%922649214.hasinit
00033   //## begin MPK_Sphere::MPK_Sphere%922649214.initialization preserve=yes
00034   : ObjectBase( frameManager ),
00035         radius( 0 )
00036   //## end MPK_Sphere::MPK_Sphere%922649214.initialization
00037 {
00038   //## begin MPK_Sphere::MPK_Sphere%922649214.body preserve=yes
00039   //## end MPK_Sphere::MPK_Sphere%922649214.body
00040 }
00041 
00042 MPK_Sphere::MPK_Sphere (const MPK_Sphere& right)
00043   //## begin MPK_Sphere::MPK_Sphere%922649215.hasinit preserve=no
00044   //## end MPK_Sphere::MPK_Sphere%922649215.hasinit
00045   //## begin MPK_Sphere::MPK_Sphere%922649215.initialization preserve=yes
00046   : ObjectBase( right )
00047   //## end MPK_Sphere::MPK_Sphere%922649215.initialization
00048 {
00049   //## begin MPK_Sphere::MPK_Sphere%922649215.body preserve=yes
00050         radius = right.radius;
00051         position = right.position;
00052   //## end MPK_Sphere::MPK_Sphere%922649215.body
00053 }
00054 
00055 
00056 MPK_Sphere::~MPK_Sphere()
00057 {
00058   //## begin MPK_Sphere::~MPK_Sphere%.body preserve=yes
00059   //## end MPK_Sphere::~MPK_Sphere%.body
00060 }
00061 
00062 
00063 
00064 //## Other Operations (implementation)
00065 Entity* MPK_Sphere::Clone () const
00066 {
00067   //## begin MPK_Sphere::Clone%922649212.body preserve=yes
00068         ObjectBase* returnme = new MPK_Sphere( *this );
00069         return returnme;
00070   //## end MPK_Sphere::Clone%922649212.body
00071 }
00072 
00073 bool MPK_Sphere::IsInterfering (const Entity* entity) const
00074 {
00075   //## begin MPK_Sphere::IsInterfering%925235848.body preserve=yes
00076         assert( CanCheckInterference( entity ) );       //IMPROVE: this should be error handled
00077         
00078         //determine the type of the entity
00079         if( dynamic_cast< const MPK_Sphere* >( entity ) != NULL )
00080         {
00081                 return( IsInterfering( dynamic_cast< const MPK_Sphere* >( entity ) ) );
00082         }
00083         if( dynamic_cast< const MPK_Cylinder* >( entity ) != NULL )
00084         {
00085                 return( IsInterfering( dynamic_cast< const MPK_Cylinder* >( entity ) ) );
00086         }
00087         else
00088         {
00089                 assert( false );        //should never get to here due to the assert( CanCheckInterference )
00090         }
00091         return false;
00092   //## end MPK_Sphere::IsInterfering%925235848.body
00093 }
00094 
00095 bool MPK_Sphere::IsInterfering (const MPK_Sphere* entity) const
00096 {
00097   //## begin MPK_Sphere::IsInterfering%925235850.body preserve=yes
00098         //find the transformation frame between the two spheres
00099         Matrix4x4 r1 = frameManager->GetTransformRelative( baseFrame, 0 );
00100         Matrix4x4 r2 = frameManager->GetTransformRelative( entity->baseFrame , 0 );
00101         Matrix4x4 relative = r1.Inverse() * r2;
00102         
00103         //calculate the distance between centers
00104         Vector4 actualP1 = theFrame * position;                                                 //IMPROVE: get rid of theFrame;
00105         Vector4 actualP2 = entity->theFrame * relative * entity->position;
00106         double dist = ( actualP1 - actualP2 ).Magnitude();
00107         if( dist > radius + entity->radius )    //IMPROVE: use MagSquared
00108         {
00109                 return false;
00110         }
00111         return true;
00112   //## end MPK_Sphere::IsInterfering%925235850.body
00113 }
00114 
00115 void MPK_Sphere::SetRadius (const double  radius)
00116 {
00117   //## begin MPK_Sphere::SetRadius%925235854.body preserve=yes
00118         this->radius = radius;
00119   //## end MPK_Sphere::SetRadius%925235854.body
00120 }
00121 
00122 Vector4 MPK_Sphere::Position () const
00123 {
00124   //## begin MPK_Sphere::Position%926709627.body preserve=yes
00125         return position;
00126   //## end MPK_Sphere::Position%926709627.body
00127 }
00128 
00129 void MPK_Sphere::SetPosition (const Vector4& position)
00130 {
00131   //## begin MPK_Sphere::SetPosition%925235855.body preserve=yes
00132         this->position = position;
00133   //## end MPK_Sphere::SetPosition%925235855.body
00134 }
00135 
00136 void MPK_Sphere::Serialize (ostream& os) const
00137 {
00138   //## begin MPK_Sphere::Serialize%934220966.body preserve=yes
00139         assert( false );
00140   //## end MPK_Sphere::Serialize%934220966.body
00141 }
00142 
00143 bool MPK_Sphere::CanCheckInterference (const Entity* entity) const
00144 {
00145   //## begin MPK_Sphere::CanCheckInterference%926300302.body preserve=yes
00146         if( dynamic_cast< const MPK_Sphere* >( entity ) != NULL )
00147         {
00148                 return true;
00149         }
00150         if( dynamic_cast< const MPK_Cylinder* >( entity ) != NULL )
00151         {
00152                 return true;
00153         }
00154         return false;
00155   //## end MPK_Sphere::CanCheckInterference%926300302.body
00156 }
00157 
00158 double MPK_Sphere::Radius () const
00159 {
00160   //## begin MPK_Sphere::Radius%926807002.body preserve=yes
00161         return radius;
00162   //## end MPK_Sphere::Radius%926807002.body
00163 }
00164 
00165 void MPK_Sphere::Deserialize (IfstreamWithComments& is)
00166 {
00167   //## begin MPK_Sphere::Deserialize%934220967.body preserve=yes
00168         assert( false );
00169   //## end MPK_Sphere::Deserialize%934220967.body
00170 }
00171 
00172 void MPK_Sphere::SetFrame (const Matrix4x4& frame)
00173 {
00174   //## begin MPK_Sphere::SetFrame%946343614.body preserve=yes
00175         //extract the position information from the frame, and alter the sphere's position
00176         Vector4 position;
00177         position[ 0 ] = frame( 0, 3 );
00178         position[ 1 ] = frame( 1, 3 );
00179         position[ 2 ] = frame( 2, 3 );
00180 
00181         this->position = position;
00182         
00183   //## end MPK_Sphere::SetFrame%946343614.body
00184 }
00185 
00186 bool MPK_Sphere::IsInterfering (const MPK_Cylinder* entity) const
00187 {
00188   //## begin MPK_Sphere::IsInterfering%970176404.body preserve=yes
00189         //determine where the end points of the sphere and cylinder are
00190         Vector4 sphereCenter = this->position;
00191         Vector4 c1 = entity->GetTransform() * Vector4( 0, 0, -entity->Height() / 2 );
00192         Vector4 c2 = entity->GetTransform() * Vector4( 0, 0,  entity->Height() / 2 );
00193 
00194 //      assert( false );
00195         return false;
00196   //## end MPK_Sphere::IsInterfering%970176404.body
00197 }
00198 
00199 bool MPK_Sphere::Verify() const
00200 {
00201         return true;
00202 }
00203 
00204 // Additional Declarations
00205   //## begin MPK_Sphere%36FE7C01006E.declarations preserve=yes
00206   //## end MPK_Sphere%36FE7C01006E.declarations
00207 
00208 //## begin module%36FE7C01006E.epilog preserve=yes
00209 //## end module%36FE7C01006E.epilog

Generated on Sat Apr 1 21:30:33 2006 for Motion Planning Kernel by  doxygen 1.4.6-NO