00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "geometry\MPK_Cylinder.h"
00016
00017
00018
00019 #include "geometry\MPK_Sphere.h"
00020
00021 #include "Kinematics\FrameManager.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030 MPK_Sphere::MPK_Sphere (FrameManager* frameManager)
00031
00032
00033
00034 : ObjectBase( frameManager ),
00035 radius( 0 )
00036
00037 {
00038
00039
00040 }
00041
00042 MPK_Sphere::MPK_Sphere (const MPK_Sphere& right)
00043
00044
00045
00046 : ObjectBase( right )
00047
00048 {
00049
00050 radius = right.radius;
00051 position = right.position;
00052
00053 }
00054
00055
00056 MPK_Sphere::~MPK_Sphere()
00057 {
00058
00059
00060 }
00061
00062
00063
00064
00065 Entity* MPK_Sphere::Clone () const
00066 {
00067
00068 ObjectBase* returnme = new MPK_Sphere( *this );
00069 return returnme;
00070
00071 }
00072
00073 bool MPK_Sphere::IsInterfering (const Entity* entity) const
00074 {
00075
00076 assert( CanCheckInterference( entity ) );
00077
00078
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 );
00090 }
00091 return false;
00092
00093 }
00094
00095 bool MPK_Sphere::IsInterfering (const MPK_Sphere* entity) const
00096 {
00097
00098
00099 Matrix4x4 r1 = frameManager->GetTransformRelative( baseFrame, 0 );
00100 Matrix4x4 r2 = frameManager->GetTransformRelative( entity->baseFrame , 0 );
00101 Matrix4x4 relative = r1.Inverse() * r2;
00102
00103
00104 Vector4 actualP1 = theFrame * position;
00105 Vector4 actualP2 = entity->theFrame * relative * entity->position;
00106 double dist = ( actualP1 - actualP2 ).Magnitude();
00107 if( dist > radius + entity->radius )
00108 {
00109 return false;
00110 }
00111 return true;
00112
00113 }
00114
00115 void MPK_Sphere::SetRadius (const double radius)
00116 {
00117
00118 this->radius = radius;
00119
00120 }
00121
00122 Vector4 MPK_Sphere::Position () const
00123 {
00124
00125 return position;
00126
00127 }
00128
00129 void MPK_Sphere::SetPosition (const Vector4& position)
00130 {
00131
00132 this->position = position;
00133
00134 }
00135
00136 void MPK_Sphere::Serialize (ostream& os) const
00137 {
00138
00139 assert( false );
00140
00141 }
00142
00143 bool MPK_Sphere::CanCheckInterference (const Entity* entity) const
00144 {
00145
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
00156 }
00157
00158 double MPK_Sphere::Radius () const
00159 {
00160
00161 return radius;
00162
00163 }
00164
00165 void MPK_Sphere::Deserialize (IfstreamWithComments& is)
00166 {
00167
00168 assert( false );
00169
00170 }
00171
00172 void MPK_Sphere::SetFrame (const Matrix4x4& frame)
00173 {
00174
00175
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
00184 }
00185
00186 bool MPK_Sphere::IsInterfering (const MPK_Cylinder* entity) const
00187 {
00188
00189
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
00195 return false;
00196
00197 }
00198
00199 bool MPK_Sphere::Verify() const
00200 {
00201 return true;
00202 }
00203
00204
00205
00206
00207
00208
00209