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 class CTransformation;
00032 class CMatrix4;
00033 
00034 //*****************************************************************************
00040 //*****************************************************************************
00041 class SICPPSDKDECL CVector4
00042 {
00043 public:
00045     SICPPSDK_INLINE CVector4();
00046 
00053     SICPPSDK_INLINE CVector4(double in_dX, double in_dY, double in_dZ, double in_dW);
00054 
00058     SICPPSDK_INLINE CVector4( const CVector4& in_vector4);
00059 
00061     SICPPSDK_INLINE ~CVector4();
00062 
00067     SICPPSDK_INLINE CVector4 & operator=( const CVector4 & in_vector4 );
00068 
00074     SICPPSDK_INLINE bool operator ==(const CVector4 & in_vector4 )const;
00075 
00081     SICPPSDK_INLINE bool operator !=(const CVector4 & in_vector4 )const;
00082 
00087     SICPPSDK_INLINE CVector4& operator ~();
00088 
00094     SICPPSDK_INLINE CVector4& operator +=(const CVector4& in_vector4);
00095 
00101     SICPPSDK_INLINE CVector4& operator -=(const CVector4 & in_vector4);
00102 
00103 
00109     SICPPSDK_INLINE CVector4& operator *=(const CMatrix4& in_matrix4);
00110 
00116     SICPPSDK_INLINE CVector4& operator *=(const CTransformation& in_transformation);
00117 
00123     SICPPSDK_INLINE CVector4& operator *=(const double& in_dAlpha);
00124 
00130     double operator[](const short& in_sIndex);
00131 
00136     SICPPSDK_INLINE CVector4& MulByMatrix4InPlace(const CMatrix4& in_matrix4);
00137 
00143     SICPPSDK_INLINE CVector4& MulByMatrix4
00144     (
00145         const CVector4& in_vector4,
00146         const CMatrix4& in_matrix4
00147     );
00148 
00153     SICPPSDK_INLINE CVector4& MulByTransformationInPlace
00154     (
00155         const CTransformation& in_transformation
00156     );
00157 
00163     SICPPSDK_INLINE CVector4& MulByTransformation
00164     (
00165         const CVector4&         in_vector4,
00166         const CTransformation&  in_transformation
00167     );
00168 
00172     SICPPSDK_INLINE CVector4& PutNull();
00173 
00177     double GetLength()const;
00178 
00182     double GetLengthSquared()const;
00183 
00187     CStatus NormalizeInPlace();
00188 
00193     CStatus Normalize(const CVector4& in_vector4);
00194 
00199     SICPPSDK_INLINE double Dot(const CVector4& in_vector4)const;
00200 
00201 
00207     SICPPSDK_INLINE CVector4& Cross(const CVector4& in_vector4A, const CVector4& in_vector4B);
00208 
00212     CVector4& AbsoluteInPlace();
00213 
00218     CVector4& Absolute(const CVector4& in_vector4);
00219 
00225     bool EpsilonEquals
00226     (
00227         const CVector4& in_vector4,
00228         double in_dEpsilon
00229     )const;
00230 
00235     SICPPSDK_INLINE bool Equals(const CVector4& in_vector4)const;
00236 
00237 
00243     SICPPSDK_INLINE CVector4& ScaleAddInPlace(double in_dS,const CVector4& in_vector4);
00244 
00251     SICPPSDK_INLINE CVector4& ScaleAdd
00252     (
00253         double          in_dS,
00254         const CVector4& in_vector4A,
00255         const CVector4& in_vector4B
00256     );
00257 
00262     SICPPSDK_INLINE CVector4& ScaleInPlace(double in_dAlpha);
00263 
00269     SICPPSDK_INLINE CVector4& Scale(double in_dAlpha, const CVector4& in_vector4);
00270 
00274     SICPPSDK_INLINE CVector4& NegateInPlace();
00275 
00280     SICPPSDK_INLINE CVector4& Negate(const CVector4& in_vector4);
00281 
00286     SICPPSDK_INLINE CVector4& SubInPlace(const CVector4& in_vector4);
00287 
00293     SICPPSDK_INLINE CVector4& Sub(const CVector4& in_vector4A, const CVector4& in_vector4B);
00294 
00299     SICPPSDK_INLINE CVector4& AddInPlace(const CVector4& in_vector4);
00300 
00306     SICPPSDK_INLINE CVector4& Add(const CVector4& in_vector4A,const CVector4& in_vector4B);
00307 
00314     SICPPSDK_INLINE void Get(   double& out_dX, double& out_dY,
00315                 double& out_dZ, double& out_dW )const;
00316 
00324     SICPPSDK_INLINE CVector4& Set(double in_dX, double in_dY, double in_dZ, double in_dW);
00325 
00329     SICPPSDK_INLINE double GetW()const;
00330 
00335     SICPPSDK_INLINE CVector4& PutW(double in_dW);
00336 
00337 
00341     SICPPSDK_INLINE double GetZ()const;
00342 
00347     SICPPSDK_INLINE CVector4& PutZ(double in_dZ);
00348 
00352     SICPPSDK_INLINE double GetY()const;
00353 
00358     SICPPSDK_INLINE CVector4& PutY(double in_dY);
00359 
00363     SICPPSDK_INLINE double GetX()const;
00364 
00369     SICPPSDK_INLINE CVector4& PutX(double in_dX);
00370 
00371 private:
00372     double m_dX,m_dY,m_dZ,m_dW;
00373 };
00374 
00375 //inline functions
00376 SICPPSDK_INLINE CVector4::CVector4(): m_dX(0.0),m_dY(0.0),m_dZ(0.0), m_dW(0.0)
00377 {}
00378 
00379 SICPPSDK_INLINE CVector4::CVector4
00380 (
00381  double in_dX, double in_dY, double in_dZ, double in_dW
00382 ):m_dX(in_dX),m_dY(in_dY),m_dZ(in_dZ), m_dW(in_dW)
00383 {}
00384 
00385 SICPPSDK_INLINE CVector4::~CVector4()
00386 {}
00387 
00388 SICPPSDK_INLINE CVector4::CVector4( const CVector4& in_vct )
00389 {
00390     in_vct.Get(m_dX,m_dY,m_dZ,m_dW);
00391 }
00392 
00393 SICPPSDK_INLINE CVector4& CVector4::operator=( const CVector4 & in_vct )
00394 {
00395     in_vct.Get(m_dX,m_dY,m_dZ,m_dW);
00396     return (*this);
00397 }
00398 
00399 
00400 SICPPSDK_INLINE bool CVector4::operator ==(const CVector4 & in_vector4 )const
00401 {
00402     return Equals(in_vector4);
00403 }
00404 
00405 
00406 SICPPSDK_INLINE bool CVector4::operator !=(const CVector4 & in_vector4 )const
00407 {
00408     return ! Equals(in_vector4);
00409 }
00410 
00411 SICPPSDK_INLINE CVector4& CVector4::operator ~()
00412 {
00413     return NegateInPlace();
00414 }
00415 
00416 SICPPSDK_INLINE CVector4& CVector4::operator +=(const CVector4& in_vector4)
00417 {
00418     return AddInPlace(in_vector4);
00419 }
00420 
00421 SICPPSDK_INLINE CVector4& CVector4::operator -=(const CVector4& in_vector4)
00422 {
00423     return SubInPlace(in_vector4);
00424 }
00425 
00426 SICPPSDK_INLINE CVector4& CVector4::operator *=(const CMatrix4& in_matrix4)
00427 {
00428     return MulByMatrix4InPlace(in_matrix4);
00429 }
00430 
00431 SICPPSDK_INLINE CVector4& CVector4::operator *=(const CTransformation& in_transformation)
00432 {
00433     return MulByTransformationInPlace(in_transformation);
00434 }
00435 
00436 SICPPSDK_INLINE CVector4& CVector4::operator *=(const double& in_dAlpha)
00437 {
00438     return ScaleInPlace(in_dAlpha);
00439 }
00440 
00441 
00442 SICPPSDK_INLINE CVector4& CVector4::MulByMatrix4InPlace
00443 (
00444     const CMatrix4& in_matrix4
00445 )
00446 {
00447     return MulByMatrix4((*this),in_matrix4);
00448 }
00449 
00450 
00451 SICPPSDK_INLINE CVector4& CVector4::MulByMatrix4
00452 (
00453     const CVector4& in_vector4,
00454     const CMatrix4& in_matrix4
00455 )
00456 {
00457     double l_dX, l_dY, l_dZ, l_dW;
00458 
00459     l_dX =  in_vector4.GetX() * in_matrix4.GetValue( 0, 0 ) +
00460             in_vector4.GetY() * in_matrix4.GetValue( 1, 0 ) +
00461             in_vector4.GetZ() * in_matrix4.GetValue( 2, 0 ) +
00462             in_vector4.GetW() * in_matrix4.GetValue( 3, 0 );
00463     l_dY =  in_vector4.GetX() * in_matrix4.GetValue( 0, 1 ) +
00464             in_vector4.GetY() * in_matrix4.GetValue( 1, 1 ) +
00465             in_vector4.GetZ() * in_matrix4.GetValue( 2, 1 ) +
00466             in_vector4.GetW() * in_matrix4.GetValue( 3, 1 );
00467     l_dZ =  in_vector4.GetX() * in_matrix4.GetValue( 0, 2 ) +
00468             in_vector4.GetY() * in_matrix4.GetValue( 1, 2 ) +
00469             in_vector4.GetZ() * in_matrix4.GetValue( 2, 2 ) +
00470             in_vector4.GetW() * in_matrix4.GetValue( 3, 2 );
00471     l_dW =  in_vector4.GetX() * in_matrix4.GetValue( 0, 3 ) +
00472             in_vector4.GetY() * in_matrix4.GetValue( 1, 3 ) +
00473             in_vector4.GetZ() * in_matrix4.GetValue( 2, 3 ) +
00474             in_vector4.GetW() * in_matrix4.GetValue( 3, 3 );
00475 
00476     return Set(l_dX, l_dY, l_dZ, l_dW);
00477 }
00478 
00479 
00480 SICPPSDK_INLINE CVector4& CVector4::MulByTransformationInPlace
00481 (
00482     const CTransformation& in_crTrans
00483 )
00484 {
00485     return MulByTransformation((*this), in_crTrans);;
00486 }
00487 
00488 
00489 SICPPSDK_INLINE CVector4& CVector4::PutNull()
00490 {
00491     m_dX = m_dY = m_dZ = m_dW = 0.0;
00492     return (*this);
00493 }
00494 
00495 
00496 SICPPSDK_INLINE double  CVector4::Dot(const CVector4& in_vector4)const
00497 {
00498 
00499     return ( m_dX*in_vector4.GetX() + m_dY*in_vector4.GetY() +
00500             m_dZ*in_vector4.GetZ() + m_dW*in_vector4.GetW());
00501 }
00502 
00503 SICPPSDK_INLINE bool CVector4::Equals(const CVector4& in_vector4)const
00504 {
00505     return (this == &in_vector4) ? true :
00506             ( ( m_dX == in_vector4.GetX() ) &&
00507               ( m_dY == in_vector4.GetY() ) &&
00508               ( m_dZ == in_vector4.GetZ() ) &&
00509               ( m_dW == in_vector4.GetW() ) );
00510 }
00511 
00512 SICPPSDK_INLINE CVector4& CVector4::ScaleAddInPlace
00513 (
00514     double in_dScalingFactor,
00515     const CVector4& in_vector4
00516 )
00517 {
00518     ScaleInPlace(in_dScalingFactor);
00519     return AddInPlace(in_vector4);
00520 }
00521 
00522 
00523 SICPPSDK_INLINE CVector4& CVector4::ScaleAdd
00524 (
00525     const double in_dScalingFactor,
00526     const CVector4& in_vector4A,
00527     const CVector4& in_vector4B
00528 )
00529 {
00530     Scale(in_dScalingFactor, in_vector4A);
00531     return AddInPlace(in_vector4B);
00532 }
00533 
00534 SICPPSDK_INLINE CVector4& CVector4::ScaleInPlace(double in_dScalingFactor)
00535 {
00536     m_dX *= in_dScalingFactor;
00537     m_dY *= in_dScalingFactor;
00538     m_dZ *= in_dScalingFactor;
00539     m_dW *= in_dScalingFactor;
00540     return (*this);
00541 }
00542 
00543 SICPPSDK_INLINE CVector4& CVector4::Scale
00544 (
00545  double in_dScalingFactor,
00546  const CVector4& in_vector4
00547 )
00548 {
00549     m_dX = in_vector4.GetX() * in_dScalingFactor;
00550     m_dY = in_vector4.GetY() * in_dScalingFactor;
00551     m_dZ = in_vector4.GetZ() * in_dScalingFactor;
00552     m_dW = in_vector4.GetW() * in_dScalingFactor;
00553     return (*this);
00554 }
00555 
00556 SICPPSDK_INLINE CVector4& CVector4::NegateInPlace()
00557 {
00558     m_dX = -m_dX;
00559     m_dY = -m_dY;
00560     m_dZ = -m_dZ;
00561     m_dW = -m_dW;
00562     return (*this);
00563 }
00564 
00565 SICPPSDK_INLINE CVector4& CVector4::Negate(const CVector4& in_vector4 )
00566 {
00567     m_dX = -in_vector4.GetX();
00568     m_dY = -in_vector4.GetY();
00569     m_dZ = -in_vector4.GetZ();
00570     m_dW = -in_vector4.GetW();
00571     return (*this);
00572 }
00573 
00574 SICPPSDK_INLINE CVector4& CVector4::SubInPlace(const CVector4& in_vector4)
00575 {
00576     m_dX -= in_vector4.GetX();
00577     m_dY -= in_vector4.GetY();
00578     m_dZ -= in_vector4.GetZ();
00579     m_dW -= in_vector4.GetW();
00580     return (*this);
00581 }
00582 
00583 SICPPSDK_INLINE CVector4& CVector4::Sub
00584 (
00585     const CVector4& in_vector4A,
00586     const CVector4& in_vector4B
00587 )
00588 {
00589     m_dX = in_vector4A.GetX() - in_vector4B.GetX();
00590     m_dY = in_vector4A.GetY() - in_vector4B.GetY();
00591     m_dZ = in_vector4A.GetZ() - in_vector4B.GetZ();
00592     m_dW = in_vector4A.GetW() - in_vector4B.GetW();
00593     return (*this);
00594 }
00595 
00596 SICPPSDK_INLINE CVector4& CVector4::AddInPlace(const CVector4& in_vector4)
00597 {
00598     m_dX += in_vector4.GetX();
00599     m_dY += in_vector4.GetY();
00600     m_dZ += in_vector4.GetZ();
00601     m_dW += in_vector4.GetW();
00602     return (*this);
00603 }
00604 
00605 SICPPSDK_INLINE CVector4& CVector4::Add
00606 (
00607     const CVector4& in_vector4A,
00608     const CVector4& in_vector4B
00609 )
00610 {
00611     m_dX = in_vector4A.GetX() + in_vector4B.GetX();
00612     m_dY = in_vector4A.GetY() + in_vector4B.GetY();
00613     m_dZ = in_vector4A.GetZ() + in_vector4B.GetZ();
00614     m_dW = in_vector4A.GetW() + in_vector4B.GetW();
00615     return (*this);
00616 }
00617 
00618 
00619 SICPPSDK_INLINE void CVector4::Get
00620 (
00621     double& out_rdX,
00622     double& out_rdY,
00623     double& out_rdZ,
00624     double& out_rdW
00625 )const
00626 {
00627     out_rdX = m_dX;
00628     out_rdY = m_dY;
00629     out_rdZ = m_dZ;
00630     out_rdW = m_dW;
00631 }
00632 
00633 SICPPSDK_INLINE CVector4& CVector4::Set
00634 (
00635     double in_dX,
00636     double in_dY,
00637     double in_dZ,
00638     double in_dW
00639 )
00640 {
00641     m_dX = in_dX;
00642     m_dY = in_dY;
00643     m_dZ = in_dZ;
00644     m_dW = in_dW;
00645     return (*this);
00646 }
00647 
00648 SICPPSDK_INLINE double CVector4::GetW()const
00649 {
00650     return m_dW;
00651 }
00652 
00653 SICPPSDK_INLINE CVector4&   CVector4::PutW(double in_dW)
00654 {
00655     m_dW = in_dW;
00656     return (*this);
00657 }
00658 
00659 SICPPSDK_INLINE double CVector4::GetZ()const
00660 {
00661     return m_dZ;
00662 }
00663 
00664 SICPPSDK_INLINE CVector4&   CVector4::PutZ(double in_dZ)
00665 {
00666     m_dZ = in_dZ;
00667     return (*this);
00668 }
00669 
00670 SICPPSDK_INLINE double CVector4::GetY()const
00671 {
00672     return m_dY;
00673 }
00674 
00675 SICPPSDK_INLINE CVector4& CVector4::PutY(double in_dY)
00676 {
00677     m_dY = in_dY;
00678     return (*this);
00679 }
00680 
00681 SICPPSDK_INLINE double CVector4::GetX()const
00682 {
00683     return m_dX;
00684 }
00685 
00686 SICPPSDK_INLINE CVector4& CVector4::PutX(double in_dX)
00687 {
00688     m_dX = in_dX;
00689     return (*this);
00690 }
00691 
00692 //*************************************************************************
00702 //*************************************************************************
00703 class SICPPSDKDECL CVector4Array
00704 {
00705 public:
00709     CVector4Array( LONG in_size=0);
00710 
00714     CVector4Array(const CVector4Array& in_ArrayToCopy);
00715 
00717     ~CVector4Array();
00718 
00723     CVector4Array& operator=( const CVector4Array& in_array );
00724 
00728     LONG GetCount() const;
00729 
00734     CStatus Add( const CVector4& in_item );
00735 
00739     CStatus Clear();
00740 
00746     CStatus Resize( LONG in_size);
00747 
00754     const CVector4& operator[]( LONG in_index ) const;
00755 
00761     CVector4& operator[]( LONG in_index );
00762 
00768     bool operator==(const CVector4Array& in_array) const;
00769 
00775     bool operator!=(const CVector4Array& in_array) const;
00776 
00777 private:
00778 
00779     void* m_ptr;
00780 };
00781 
00782 };
00783 };
00784 
00785 #endif // __XSIVECTOR4_H__