xsi_plane.h Source File
 
 
 
xsi_plane.h
Go to the documentation of this file.
00001 //*****************************************************************************
00011 //*****************************************************************************
00012 
00013 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00014 #pragma once
00015 #endif
00016 
00017 #ifndef __XSIPLANE_H__
00018 #define __XSIPLANE_H__
00019 
00020 #include "sicppsdk.h"
00021 #include "xsi_status.h"
00022 #include "xsi_vector3.h"
00023 #include "xsi_line.h"
00024 #include <math.h>
00025 
00026 namespace XSI {
00027 
00028 namespace MATH {
00029 
00030 //*****************************************************************************
00040 //*****************************************************************************
00041 class SICPPSDKDECL CPlane
00042 {
00043 public:
00045         SICPPSDK_INLINE CPlane();
00046 
00051         SICPPSDK_INLINE CPlane( const CVector3 &in_point, const CVector3 &in_normal );
00052 
00058         SICPPSDK_INLINE CPlane( const CVector3 &in_point, const CVector3 &in_tangentU, const CVector3 &in_tangentV );
00059 
00063         SICPPSDK_INLINE CPlane( const CPlane &in_plane );
00064 
00066         SICPPSDK_INLINE ~CPlane();
00067 
00072         SICPPSDK_INLINE CPlane & operator=( const CPlane & in_plane );
00073 
00079         SICPPSDK_INLINE bool operator ==(const CPlane &in_plane )const;
00080 
00086         SICPPSDK_INLINE bool operator !=(const CPlane &in_plane )const;
00087 
00094         SICPPSDK_INLINE bool EpsilonEquals(const CPlane &in_plane, double in_dEpsilon)const;
00095 
00100         SICPPSDK_INLINE bool Equals(const CPlane &in_plane)const;
00101 
00106         bool Parallel(const CPlane &in_plane)const;
00107 
00112         bool Coplanar(const CPlane &in_plane)const;
00113 
00117         SICPPSDK_INLINE double GetDistance(const CVector3 &in_point)const;
00118 
00124         SICPPSDK_INLINE CVector3 GetPosition(double in_U, double inV)const;
00125 
00130         void GetParameters(const CVector3 &in_point, double &out_U, double &out_V)const;
00131 
00137         bool Intersect(const CLine &in_line, CVector3 &out_point)const;
00138 
00142         SICPPSDK_INLINE CVector3 Project(const CVector3 &in_point)const;
00143 
00147         SICPPSDK_INLINE CVector3 Reflect(const CVector3 &in_point)const;
00148 
00152         SICPPSDK_INLINE CLine ProjectLine(const CLine &in_line)const;
00153 
00157         SICPPSDK_INLINE CLine ReflectLine(const CLine &in_line)const;
00158 
00163         CMatrix4 & GetMirrorTransform(CMatrix4 &out_matrix4)const;
00164 
00168         SICPPSDK_INLINE const CVector3 &GetOrigin()const;
00169 
00173         SICPPSDK_INLINE const CVector3 &GetNormal()const;
00174 
00178         SICPPSDK_INLINE const CVector3 &GetTangentU()const;
00179 
00183         SICPPSDK_INLINE const CVector3 &GetTangentV()const;
00184 
00189         SICPPSDK_INLINE CPlane &SetOrigin(const CVector3 &in_point);
00190 
00195         CPlane &SetNormal(const CVector3 &in_normal);
00196 
00202         CPlane &SetTangents(const CVector3 &in_U, const CVector3 &in_V);
00203 
00209         SICPPSDK_INLINE CPlane &Set(const CVector3 &in_point, const CVector3 &in_normal);
00210 
00217         SICPPSDK_INLINE CPlane &Set(const CVector3 &in_point, const CVector3 &in_U, const CVector3 &in_V);
00218 
00224         SICPPSDK_INLINE CPlane& operator *=(const CMatrix3& in_matrix3);
00225 
00231         SICPPSDK_INLINE CPlane& operator *=(const CMatrix4& in_matrix4);
00232 
00238         SICPPSDK_INLINE CPlane& operator *=(const CTransformation& in_transformation);
00239 
00244         SICPPSDK_INLINE CPlane& MulByMatrix3InPlace(const CMatrix3& in_matrix3);
00245 
00251         SICPPSDK_INLINE CPlane& MulByMatrix3(const CPlane &in_plane, const CMatrix3 &in_matrix3);
00252 
00257         SICPPSDK_INLINE CPlane& MulByMatrix4InPlace(const CMatrix4& in_matrix4);
00258 
00264         SICPPSDK_INLINE CPlane& MulByMatrix4(const CPlane &in_plane, const CMatrix4 &in_matrix4);
00265 
00270         SICPPSDK_INLINE CPlane& MulByTransformationInPlace(const CTransformation &in_transformation);
00271 
00277         SICPPSDK_INLINE CPlane& MulByTransformation(const CPlane &in_plane, const CTransformation &in_transformation);
00278 
00279 private:
00280         CVector3        m_vOrigin;
00281         CVector3        m_vNormal;
00282         CVector3        m_vTangentU;
00283         CVector3        m_vTangentV;
00284 };
00285 
00286 //inline functions
00287 SICPPSDK_INLINE CPlane::CPlane()
00288 : m_vOrigin(0.0, 0.0, 0.0), m_vTangentU(1.0, 0.0, 0.0), m_vTangentV(0.0, 1.0, 0.0), m_vNormal( 0.0, 0.0, 1.0 )
00289 {
00290 }
00291 
00292 SICPPSDK_INLINE CPlane::CPlane( const CPlane& in_plane )
00293 : m_vOrigin(in_plane.m_vOrigin), m_vTangentU(in_plane.m_vTangentU), m_vTangentV(in_plane.m_vTangentV), m_vNormal(in_plane.m_vNormal)
00294 {
00295 }
00296 
00297 SICPPSDK_INLINE CPlane::~CPlane()
00298 {}
00299 
00300 SICPPSDK_INLINE CPlane::CPlane( const CVector3 &in_pt, const CVector3 &in_normal )
00301 : m_vOrigin(in_pt)
00302 {
00303         SetNormal( in_normal );
00304 }
00305 
00306 SICPPSDK_INLINE CPlane::CPlane( const CVector3 &in_pt, const CVector3 &in_U, const CVector3 &in_V )
00307 : m_vOrigin(in_pt)
00308 {
00309         SetTangents( in_U, in_V );
00310 }
00311 
00312 SICPPSDK_INLINE CPlane& CPlane::operator=( const CPlane & in_plane )
00313 {
00314         m_vOrigin   = in_plane.m_vOrigin;
00315         m_vNormal   = in_plane.m_vNormal;
00316         m_vTangentU = in_plane.m_vTangentU;
00317         m_vTangentV = in_plane.m_vTangentV;
00318         return *this;
00319 }
00320 
00321 SICPPSDK_INLINE const CVector3 &CPlane::GetOrigin()const
00322 {
00323         return m_vOrigin;
00324 }
00325 
00326 SICPPSDK_INLINE const CVector3 &CPlane::GetNormal()const
00327 {
00328         return m_vNormal;
00329 }
00330 
00331 SICPPSDK_INLINE const CVector3 &CPlane::GetTangentU()const
00332 {
00333         return m_vTangentU;
00334 }
00335 
00336 SICPPSDK_INLINE const CVector3 &CPlane::GetTangentV()const
00337 {
00338         return m_vTangentV;
00339 }
00340 
00341 SICPPSDK_INLINE CPlane & CPlane::Set(const CVector3 &in_point, const CVector3 &in_normal)
00342 {
00343         return SetOrigin( in_point ).SetNormal( in_normal );
00344 }
00345 
00346 SICPPSDK_INLINE CPlane & CPlane::Set(const CVector3 &in_point, const CVector3 &in_U, const CVector3 &in_V)
00347 {
00348         return SetOrigin( in_point ).SetTangents( in_U, in_V );
00349 }
00350 
00351 SICPPSDK_INLINE bool CPlane::EpsilonEquals(const CPlane& in_plane, double in_dEpsilon)const
00352 {
00353         return (this == &in_plane ? true :
00354                         (m_vOrigin.EpsilonEquals(in_plane.m_vOrigin, in_dEpsilon) &&
00355                          m_vNormal.EpsilonEquals(in_plane.m_vNormal, in_dEpsilon) &&
00356                          m_vTangentU.EpsilonEquals(in_plane.m_vTangentU, in_dEpsilon) &&
00357                          m_vTangentV.EpsilonEquals(in_plane.m_vTangentV, in_dEpsilon)));
00358 }
00359 
00360 
00361 SICPPSDK_INLINE bool CPlane::Equals(const CPlane& in_plane)const
00362 {
00363         return (this == &in_plane ? true :
00364                         (m_vOrigin.Equals(in_plane.m_vOrigin) &&
00365                          m_vNormal.Equals(in_plane.m_vNormal) &&
00366                          m_vTangentU.Equals(in_plane.m_vTangentU) &&
00367                          m_vTangentV.Equals(in_plane.m_vTangentV)));
00368 }
00369 
00370 SICPPSDK_INLINE bool CPlane::operator ==(const CPlane & in_plane )const
00371 {
00372         return Equals(in_plane);
00373 }
00374 
00375 SICPPSDK_INLINE bool CPlane::operator !=(const CPlane & in_plane )const
00376 {
00377         return !Equals(in_plane);
00378 }
00379 
00380 SICPPSDK_INLINE CVector3 CPlane::GetPosition(double in_u, double in_v)const
00381 {
00382         CVector3 l_Tmp, l_Result( m_vOrigin );
00383         l_Result.AddInPlace( l_Tmp.Scale( in_u, m_vTangentU ) );
00384         l_Result.AddInPlace( l_Tmp.Scale( in_v, m_vTangentV ) );
00385         return l_Result;
00386 }
00387 
00388 SICPPSDK_INLINE CPlane & CPlane::SetOrigin(const CVector3 &in_point)
00389 {
00390         m_vOrigin = in_point;
00391         return *this;
00392 }
00393 
00394 SICPPSDK_INLINE CVector3 CPlane::Project(const CVector3 &in_point)const
00395 {
00396         double l_dU = 0.0, l_dV = 0.0;
00397         GetParameters( in_point, l_dU, l_dV );
00398         return GetPosition(l_dU, l_dV);
00399 }
00400 
00401 SICPPSDK_INLINE CVector3 CPlane::Reflect(const CVector3 &in_point)const
00402 {
00403         return Project(in_point).ScaleInPlace(2.0).SubInPlace(in_point);
00404 }
00405 
00406 SICPPSDK_INLINE CLine CPlane::ProjectLine(const CLine &in_line)const
00407 {
00408         CVector3 l_Origin  = Project( in_line.GetOrigin() );
00409         CVector3 l_Tangent = Project( in_line.GetPosition( 1.0 ) ).SubInPlace( l_Origin );
00410         return CLine( l_Origin, l_Tangent );
00411 }
00412 
00413 SICPPSDK_INLINE CLine CPlane::ReflectLine(const CLine &in_line)const
00414 {
00415         CVector3 l_Origin  = Reflect( in_line.GetOrigin() );
00416         CVector3 l_Tangent = Reflect( in_line.GetPosition( 1.0 ) ).SubInPlace( l_Origin );
00417         return CLine( l_Origin, l_Tangent );
00418 }
00419 
00420 SICPPSDK_INLINE double CPlane::GetDistance(const CVector3 &in_point)const
00421 {
00422         return Project(in_point).SubInPlace(in_point).GetLength();
00423 }
00424 
00425 SICPPSDK_INLINE CPlane& CPlane::MulByMatrix3(const CPlane& in_plane, const CMatrix3& in_matrix3)
00426 {
00427         CVector3 l_NewOrigin, l_NewU, l_NewV;
00428         l_NewOrigin.MulByMatrix3(in_plane.m_vOrigin, in_matrix3);
00429         l_NewU.Add(in_plane.m_vOrigin, in_plane.m_vTangentU).MulByMatrix3InPlace(in_matrix3).SubInPlace(l_NewOrigin);
00430         l_NewV.Add(in_plane.m_vOrigin, in_plane.m_vTangentV).MulByMatrix3InPlace(in_matrix3).SubInPlace(l_NewOrigin);
00431         return Set(l_NewOrigin, l_NewU, l_NewV);
00432 }
00433 
00434 SICPPSDK_INLINE CPlane& CPlane::MulByMatrix4(const CPlane& in_plane, const CMatrix4& in_matrix4)
00435 {
00436         CVector3 l_NewOrigin, l_NewU, l_NewV;
00437         l_NewOrigin.MulByMatrix4(in_plane.m_vOrigin, in_matrix4);
00438         l_NewU.Add(in_plane.m_vOrigin, in_plane.m_vTangentU).MulByMatrix4InPlace(in_matrix4).SubInPlace(l_NewOrigin);
00439         l_NewV.Add(in_plane.m_vOrigin, in_plane.m_vTangentV).MulByMatrix4InPlace(in_matrix4).SubInPlace(l_NewOrigin);
00440         return Set(l_NewOrigin, l_NewU, l_NewV);
00441 }
00442 
00443 SICPPSDK_INLINE CPlane& CPlane::MulByTransformation(const CPlane &in_plane, const CTransformation &in_transformation)
00444 {
00445         CVector3 l_NewOrigin, l_NewU, l_NewV;
00446         l_NewOrigin.MulByTransformation(in_plane.m_vOrigin, in_transformation);
00447         l_NewU.Add(in_plane.m_vOrigin, in_plane.m_vTangentU).MulByTransformationInPlace(in_transformation).SubInPlace(l_NewOrigin);
00448         l_NewV.Add(in_plane.m_vOrigin, in_plane.m_vTangentV).MulByTransformationInPlace(in_transformation).SubInPlace(l_NewOrigin);
00449         return Set(l_NewOrigin, l_NewU, l_NewV);
00450 }
00451 
00452 SICPPSDK_INLINE CPlane& CPlane::MulByMatrix3InPlace(const CMatrix3& in_matrix3)
00453 {
00454         return MulByMatrix3(*this, in_matrix3);
00455 }
00456 
00457 SICPPSDK_INLINE CPlane& CPlane::MulByMatrix4InPlace(const CMatrix4& in_matrix4)
00458 {
00459         return MulByMatrix4(*this, in_matrix4);
00460 }
00461 
00462 SICPPSDK_INLINE CPlane& CPlane::MulByTransformationInPlace(const CTransformation& in_crTrans)
00463 {
00464         return MulByTransformation(*this, in_crTrans);
00465 }
00466 
00467 SICPPSDK_INLINE CPlane& CPlane::operator *=(const CMatrix3& in_matrix3)
00468 {
00469         return MulByMatrix3InPlace(in_matrix3);
00470 }
00471 
00472 SICPPSDK_INLINE CPlane& CPlane::operator *=(const CMatrix4& in_matrix4)
00473 {
00474         return MulByMatrix4InPlace(in_matrix4);
00475 }
00476 
00477 SICPPSDK_INLINE CPlane& CPlane::operator *=(const CTransformation& in_transformation)
00478 {
00479         return MulByTransformationInPlace(in_transformation);
00480 }
00481 
00482 };
00483 };
00484 
00485 #endif // __XSIPLANE_H__