xsi_vector4.h Source File
 
 
 
xsi_vector4.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 __XSIVECTOR4_H__
00018 #define __XSIVECTOR4_H__
00019 
00020 #include "sicppsdk.h"
00021 #include "xsi_status.h"
00022 #include "xsi_matrix4.h"
00023 #include "xsi_transformation.h"
00024 
00025 
00026 namespace XSI {
00027 
00028 
00029 namespace MATH {
00030 
00031 //*****************************************************************************
00037 //*****************************************************************************
00038 class SICPPSDKDECL CVector4
00039 {
00040 public:
00042         SICPPSDK_INLINE CVector4();
00043 
00050         SICPPSDK_INLINE CVector4(double in_dX, double in_dY, double in_dZ, double in_dW);
00051 
00055         SICPPSDK_INLINE CVector4( const CVector4& in_vector4);
00056 
00058         SICPPSDK_INLINE ~CVector4();
00059 
00064         SICPPSDK_INLINE CVector4 & operator=( const CVector4 & in_vector4 );
00065 
00071         SICPPSDK_INLINE bool operator ==(const CVector4 & in_vector4 )const;
00072 
00078         SICPPSDK_INLINE bool operator !=(const CVector4 & in_vector4 )const;
00079 
00084         SICPPSDK_INLINE CVector4& operator ~();
00085 
00091         SICPPSDK_INLINE CVector4& operator +=(const CVector4& in_vector4);
00092 
00098         SICPPSDK_INLINE CVector4& operator -=(const CVector4 & in_vector4);
00099 
00100 
00106         SICPPSDK_INLINE CVector4& operator *=(const CMatrix4& in_matrix4);
00107 
00113         SICPPSDK_INLINE CVector4& operator *=(const CTransformation& in_transformation);
00114 
00120         SICPPSDK_INLINE CVector4& operator *=(const double& in_dAlpha);
00121 
00127         double operator[](const short& in_sIndex);
00128 
00133         SICPPSDK_INLINE CVector4& MulByMatrix4InPlace(const CMatrix4& in_matrix4);
00134 
00140         SICPPSDK_INLINE CVector4& MulByMatrix4
00141         (
00142                 const CVector4& in_vector4,
00143                 const CMatrix4& in_matrix4
00144         );
00145 
00150         SICPPSDK_INLINE CVector4& MulByTransformationInPlace
00151         (
00152                 const CTransformation& in_transformation
00153         );
00154 
00160         SICPPSDK_INLINE CVector4& MulByTransformation
00161         (
00162                 const CVector4&                 in_vector4,
00163                 const CTransformation&  in_transformation
00164         );
00165 
00169         SICPPSDK_INLINE CVector4& PutNull();
00170 
00174         double GetLength()const;
00175 
00179         double GetLengthSquared()const;
00180 
00184         CStatus NormalizeInPlace();
00185 
00190         CStatus Normalize(const CVector4& in_vector4);
00191 
00196         SICPPSDK_INLINE double Dot(const CVector4& in_vector4)const;
00197 
00198 
00204         SICPPSDK_INLINE CVector4& Cross(const CVector4& in_vector4A, const CVector4& in_vector4B);
00205 
00209         CVector4& AbsoluteInPlace();
00210 
00215         CVector4& Absolute(const CVector4& in_vector4);
00216 
00222         bool EpsilonEquals
00223         (
00224                 const CVector4& in_vector4,
00225                 double in_dEpsilon
00226         )const;
00227 
00232         SICPPSDK_INLINE bool Equals(const CVector4& in_vector4)const;
00233 
00234 
00240         SICPPSDK_INLINE CVector4& ScaleAddInPlace(double in_dS,const CVector4& in_vector4);
00241 
00248         SICPPSDK_INLINE CVector4& ScaleAdd
00249         (
00250                 double                  in_dS,
00251                 const CVector4& in_vector4A,
00252                 const CVector4& in_vector4B
00253         );
00254 
00259         SICPPSDK_INLINE CVector4& ScaleInPlace(double in_dAlpha);
00260 
00266         SICPPSDK_INLINE CVector4& Scale(double in_dAlpha, const CVector4& in_vector4);
00267 
00271         SICPPSDK_INLINE CVector4& NegateInPlace();
00272 
00277         SICPPSDK_INLINE CVector4& Negate(const CVector4& in_vector4);
00278 
00283         SICPPSDK_INLINE CVector4& SubInPlace(const CVector4& in_vector4);
00284 
00291         SICPPSDK_INLINE CVector4& Sub(const CVector4& in_vector4A, const CVector4& in_vector4B);
00292 
00297         SICPPSDK_INLINE CVector4& AddInPlace(const CVector4& in_vector4);
00298 
00304         SICPPSDK_INLINE CVector4& Add(const CVector4& in_vector4A,const CVector4& in_vector4B);
00305 
00312         SICPPSDK_INLINE void Get(       double& out_dX, double& out_dY,
00313                                 double& out_dZ, double& out_dW )const;
00314 
00322         SICPPSDK_INLINE CVector4& Set(double in_dX, double in_dY, double in_dZ, double in_dW);
00323 
00327         SICPPSDK_INLINE double GetW()const;
00328 
00333         SICPPSDK_INLINE CVector4& PutW(double in_dW);
00334 
00335 
00339         SICPPSDK_INLINE double GetZ()const;
00340 
00345         SICPPSDK_INLINE CVector4& PutZ(double in_dZ);
00346 
00350         SICPPSDK_INLINE double GetY()const;
00351 
00356         SICPPSDK_INLINE CVector4& PutY(double in_dY);
00357 
00361         SICPPSDK_INLINE double GetX()const;
00362 
00367         SICPPSDK_INLINE CVector4& PutX(double in_dX);
00368 
00369 private:
00370         double m_dX,m_dY,m_dZ,m_dW;
00371 };
00372 
00373 //inline functions
00374 SICPPSDK_INLINE CVector4::CVector4(): m_dX(0.0),m_dY(0.0),m_dZ(0.0), m_dW(0.0)
00375 {}
00376 
00377 SICPPSDK_INLINE CVector4::CVector4
00378 (
00379  double in_dX, double in_dY, double in_dZ, double in_dW
00380 ):m_dX(in_dX),m_dY(in_dY),m_dZ(in_dZ), m_dW(in_dW)
00381 {}
00382 
00383 SICPPSDK_INLINE CVector4::~CVector4()
00384 {}
00385 
00386 SICPPSDK_INLINE CVector4::CVector4( const CVector4& in_vct )
00387 {
00388         in_vct.Get(m_dX,m_dY,m_dZ,m_dW);
00389 }
00390 
00391 SICPPSDK_INLINE CVector4& CVector4::operator=( const CVector4 & in_vct )
00392 {
00393         in_vct.Get(m_dX,m_dY,m_dZ,m_dW);
00394         return (*this);
00395 }
00396 
00397 
00398 SICPPSDK_INLINE bool CVector4::operator ==(const CVector4 & in_vector4 )const
00399 {
00400         return Equals(in_vector4);
00401 }
00402 
00403 
00404 SICPPSDK_INLINE bool CVector4::operator !=(const CVector4 & in_vector4 )const
00405 {
00406         return ! Equals(in_vector4);
00407 }
00408 
00409 SICPPSDK_INLINE CVector4& CVector4::operator ~()
00410 {
00411         return NegateInPlace();
00412 }
00413 
00414 SICPPSDK_INLINE CVector4& CVector4::operator +=(const CVector4& in_vector4)
00415 {
00416         return AddInPlace(in_vector4);
00417 }
00418 
00419 SICPPSDK_INLINE CVector4& CVector4::operator -=(const CVector4& in_vector4)
00420 {
00421         return SubInPlace(in_vector4);
00422 }
00423 
00424 SICPPSDK_INLINE CVector4& CVector4::operator *=(const CMatrix4& in_matrix4)
00425 {
00426         return MulByMatrix4InPlace(in_matrix4);
00427 }
00428 
00429 SICPPSDK_INLINE CVector4& CVector4::operator *=(const CTransformation& in_transformation)
00430 {
00431         return MulByTransformationInPlace(in_transformation);
00432 }
00433 
00434 SICPPSDK_INLINE CVector4& CVector4::operator *=(const double& in_dAlpha)
00435 {
00436         return ScaleInPlace(in_dAlpha);
00437 }
00438 
00439 
00440 SICPPSDK_INLINE CVector4& CVector4::MulByMatrix4InPlace
00441 (
00442         const CMatrix4& in_matrix4
00443 )
00444 {
00445         return MulByMatrix4((*this),in_matrix4);
00446 }
00447 
00448 
00449 SICPPSDK_INLINE CVector4& CVector4::MulByMatrix4
00450 (
00451         const CVector4& in_vector4,
00452         const CMatrix4& in_matrix4
00453 )
00454 {
00455         double l_dX, l_dY, l_dZ, l_dW;
00456 
00457         l_dX =  in_vector4.GetX() * in_matrix4.GetValue( 0, 0 ) +
00458                         in_vector4.GetY() * in_matrix4.GetValue( 1, 0 ) +
00459                         in_vector4.GetZ() * in_matrix4.GetValue( 2, 0 ) +
00460                         in_vector4.GetW() * in_matrix4.GetValue( 3, 0 );
00461         l_dY =  in_vector4.GetX() * in_matrix4.GetValue( 0, 1 ) +
00462                         in_vector4.GetY() * in_matrix4.GetValue( 1, 1 ) +
00463                         in_vector4.GetZ() * in_matrix4.GetValue( 2, 1 ) +
00464                         in_vector4.GetW() * in_matrix4.GetValue( 3, 1 );
00465         l_dZ =  in_vector4.GetX() * in_matrix4.GetValue( 0, 2 ) +
00466                         in_vector4.GetY() * in_matrix4.GetValue( 1, 2 ) +
00467                         in_vector4.GetZ() * in_matrix4.GetValue( 2, 2 ) +
00468                         in_vector4.GetW() * in_matrix4.GetValue( 3, 2 );
00469         l_dW =  in_vector4.GetX() * in_matrix4.GetValue( 0, 3 ) +
00470                         in_vector4.GetY() * in_matrix4.GetValue( 1, 3 ) +
00471                         in_vector4.GetZ() * in_matrix4.GetValue( 2, 3 ) +
00472                         in_vector4.GetW() * in_matrix4.GetValue( 3, 3 );
00473 
00474         return Set(l_dX, l_dY, l_dZ, l_dW);
00475 }
00476 
00477 
00478 SICPPSDK_INLINE CVector4& CVector4::MulByTransformationInPlace
00479 (
00480         const CTransformation& in_crTrans
00481 )
00482 {
00483         return MulByTransformation((*this), in_crTrans);
00484 }
00485 
00486 
00487 SICPPSDK_INLINE CVector4& CVector4::MulByTransformation
00488 (
00489         const CVector4& in_vector4,
00490         const CTransformation& in_trans
00491 )
00492 {
00493         CMatrix4 l_matrix4 = in_trans.GetMatrix4();
00494 
00495         double l_dX, l_dY, l_dZ, l_dW;
00496 
00497         l_dX =  in_vector4.GetX() * l_matrix4.GetValue( 0, 0 ) +
00498                         in_vector4.GetY() * l_matrix4.GetValue( 1, 0 ) +
00499                         in_vector4.GetZ() * l_matrix4.GetValue( 2, 0 ) +
00500                         in_vector4.GetW() * l_matrix4.GetValue( 3, 0 );
00501         l_dY =  in_vector4.GetX() * l_matrix4.GetValue( 0, 1 ) +
00502                         in_vector4.GetY() * l_matrix4.GetValue( 1, 1 ) +
00503                         in_vector4.GetZ() * l_matrix4.GetValue( 2, 1 ) +
00504                         in_vector4.GetW() * l_matrix4.GetValue( 3, 1 );
00505         l_dZ =  in_vector4.GetX() * l_matrix4.GetValue( 0, 2 ) +
00506                         in_vector4.GetY() * l_matrix4.GetValue( 1, 2 ) +
00507                         in_vector4.GetZ() * l_matrix4.GetValue( 2, 2 ) +
00508                         in_vector4.GetW() * l_matrix4.GetValue( 3, 2 );
00509         l_dW =  in_vector4.GetX() * l_matrix4.GetValue( 0, 3 ) +
00510                         in_vector4.GetY() * l_matrix4.GetValue( 1, 3 ) +
00511                         in_vector4.GetZ() * l_matrix4.GetValue( 2, 3 ) +
00512                         in_vector4.GetW() * l_matrix4.GetValue( 3, 3 );
00513 
00514 
00515         return Set(l_dX, l_dY, l_dZ, l_dW);
00516 }
00517 
00518 
00519 SICPPSDK_INLINE CVector4& CVector4::PutNull()
00520 {
00521         m_dX = m_dY = m_dZ = m_dW = 0.0;
00522         return (*this);
00523 }
00524 
00525 
00526 SICPPSDK_INLINE double  CVector4::Dot(const CVector4& in_vector4)const
00527 {
00528 
00529         return ( m_dX*in_vector4.GetX() + m_dY*in_vector4.GetY() +
00530                         m_dZ*in_vector4.GetZ() + m_dW*in_vector4.GetW());
00531 }
00532 
00533 SICPPSDK_INLINE bool CVector4::Equals(const CVector4& in_vector4)const
00534 {
00535         return (this == &in_vector4) ? true :
00536                         ( ( m_dX == in_vector4.GetX() ) &&
00537                           ( m_dY == in_vector4.GetY() ) &&
00538                           ( m_dZ == in_vector4.GetZ() ) &&
00539                           ( m_dW == in_vector4.GetW() ) );
00540 }
00541 
00542 SICPPSDK_INLINE CVector4& CVector4::ScaleAddInPlace
00543 (
00544         double in_dScalingFactor,
00545         const CVector4& in_vector4
00546 )
00547 {
00548         ScaleInPlace(in_dScalingFactor);
00549         return AddInPlace(in_vector4);
00550 }
00551 
00552 
00553 SICPPSDK_INLINE CVector4& CVector4::ScaleAdd
00554 (
00555         const double in_dScalingFactor,
00556         const CVector4& in_vector4A,
00557         const CVector4& in_vector4B
00558 )
00559 {
00560         Scale(in_dScalingFactor, in_vector4A);
00561         return AddInPlace(in_vector4B);
00562 }
00563 
00564 SICPPSDK_INLINE CVector4& CVector4::ScaleInPlace(double in_dScalingFactor)
00565 {
00566         m_dX *= in_dScalingFactor;
00567         m_dY *= in_dScalingFactor;
00568         m_dZ *= in_dScalingFactor;
00569         m_dW *= in_dScalingFactor;
00570         return (*this);
00571 }
00572 
00573 SICPPSDK_INLINE CVector4& CVector4::Scale
00574 (
00575  double in_dScalingFactor,
00576  const CVector4& in_vector4
00577 )
00578 {
00579         m_dX = in_vector4.GetX() * in_dScalingFactor;
00580         m_dY = in_vector4.GetY() * in_dScalingFactor;
00581         m_dZ = in_vector4.GetZ() * in_dScalingFactor;
00582         m_dW = in_vector4.GetW() * in_dScalingFactor;
00583         return (*this);
00584 }
00585 
00586 SICPPSDK_INLINE CVector4& CVector4::NegateInPlace()
00587 {
00588         m_dX = -m_dX;
00589         m_dY = -m_dY;
00590         m_dZ = -m_dZ;
00591         m_dW = -m_dW;
00592         return (*this);
00593 }
00594 
00595 SICPPSDK_INLINE CVector4& CVector4::Negate(const CVector4& in_vector4 )
00596 {
00597         m_dX = -in_vector4.GetX();
00598         m_dY = -in_vector4.GetY();
00599         m_dZ = -in_vector4.GetZ();
00600         m_dW = -in_vector4.GetW();
00601         return (*this);
00602 }
00603 
00604 SICPPSDK_INLINE CVector4& CVector4::SubInPlace(const CVector4& in_vector4)
00605 {
00606         m_dX -= in_vector4.GetX();
00607         m_dY -= in_vector4.GetY();
00608         m_dZ -= in_vector4.GetZ();
00609         m_dW -= in_vector4.GetW();
00610         return (*this);
00611 }
00612 
00613 SICPPSDK_INLINE CVector4& CVector4::Sub
00614 (
00615         const CVector4& in_vector4A,
00616         const CVector4& in_vector4B
00617 )
00618 {
00619         m_dX = in_vector4A.GetX() - in_vector4B.GetX();
00620         m_dY = in_vector4A.GetY() - in_vector4B.GetY();
00621         m_dZ = in_vector4A.GetZ() - in_vector4B.GetZ();
00622         m_dW = in_vector4A.GetW() - in_vector4B.GetW();
00623         return (*this);
00624 }
00625 
00626 SICPPSDK_INLINE CVector4& CVector4::AddInPlace(const CVector4& in_vector4)
00627 {
00628         m_dX += in_vector4.GetX();
00629         m_dY += in_vector4.GetY();
00630         m_dZ += in_vector4.GetZ();
00631         m_dW += in_vector4.GetW();
00632         return (*this);
00633 }
00634 
00635 SICPPSDK_INLINE CVector4& CVector4::Add
00636 (
00637         const CVector4& in_vector4A,
00638         const CVector4& in_vector4B
00639 )
00640 {
00641         m_dX = in_vector4A.GetX() + in_vector4B.GetX();
00642         m_dY = in_vector4A.GetY() + in_vector4B.GetY();
00643         m_dZ = in_vector4A.GetZ() + in_vector4B.GetZ();
00644         m_dW = in_vector4A.GetW() + in_vector4B.GetW();
00645         return (*this);
00646 }
00647 
00648 
00649 SICPPSDK_INLINE void CVector4::Get
00650 (
00651         double& out_rdX,
00652         double& out_rdY,
00653         double& out_rdZ,
00654         double& out_rdW
00655 )const
00656 {
00657         out_rdX = m_dX;
00658         out_rdY = m_dY;
00659         out_rdZ = m_dZ;
00660         out_rdW = m_dW;
00661 }
00662 
00663 SICPPSDK_INLINE CVector4& CVector4::Set
00664 (
00665         double in_dX,
00666         double in_dY,
00667         double in_dZ,
00668         double in_dW
00669 )
00670 {
00671         m_dX = in_dX;
00672         m_dY = in_dY;
00673         m_dZ = in_dZ;
00674         m_dW = in_dW;
00675         return (*this);
00676 }
00677 
00678 SICPPSDK_INLINE double CVector4::GetW()const
00679 {
00680         return m_dW;
00681 }
00682 
00683 SICPPSDK_INLINE CVector4&       CVector4::PutW(double in_dW)
00684 {
00685         m_dW = in_dW;
00686         return (*this);
00687 }
00688 
00689 SICPPSDK_INLINE double CVector4::GetZ()const
00690 {
00691         return m_dZ;
00692 }
00693 
00694 SICPPSDK_INLINE CVector4&       CVector4::PutZ(double in_dZ)
00695 {
00696         m_dZ = in_dZ;
00697         return (*this);
00698 }
00699 
00700 SICPPSDK_INLINE double CVector4::GetY()const
00701 {
00702         return m_dY;
00703 }
00704 
00705 SICPPSDK_INLINE CVector4& CVector4::PutY(double in_dY)
00706 {
00707         m_dY = in_dY;
00708         return (*this);
00709 }
00710 
00711 SICPPSDK_INLINE double CVector4::GetX()const
00712 {
00713         return m_dX;
00714 }
00715 
00716 SICPPSDK_INLINE CVector4& CVector4::PutX(double in_dX)
00717 {
00718         m_dX = in_dX;
00719         return (*this);
00720 }
00721 
00722 //*************************************************************************
00732 //*************************************************************************
00733 class SICPPSDKDECL CVector4Array
00734 {
00735 public:
00739         CVector4Array( LONG in_size=0);
00740 
00744         CVector4Array(const CVector4Array& in_ArrayToCopy);
00745 
00747         ~CVector4Array();
00748 
00753         CVector4Array& operator=( const CVector4Array& in_array );
00754 
00758         LONG GetCount() const;
00759 
00764         CStatus Add( const CVector4& in_item );
00765 
00769         CStatus Clear();
00770 
00776         CStatus Resize( LONG in_size);
00777 
00784         const CVector4& operator[]( LONG in_index ) const;
00785 
00791         CVector4& operator[]( LONG in_index );
00792 
00798         bool operator==(const CVector4Array& in_array) const;
00799 
00805         bool operator!=(const CVector4Array& in_array) const;
00806 
00807 private:
00808 
00809         void* m_ptr;
00810 };
00811 
00812 };
00813 };
00814 
00815 #endif // __XSIVECTOR4_H__