xsi_vector4f.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 __XSIVECTOR4F_H__
00018 #define __XSIVECTOR4F_H__
00019 
00020 #include "sicppsdk.h"
00021 #include "xsi_matrix4f.h"
00022 
00023 namespace XSI {
00024 
00025 namespace MATH {
00026 
00027 //*****************************************************************************
00034 //*****************************************************************************
00035 class SICPPSDKDECL CVector4f
00036 {
00037 public:
00039     SICPPSDK_INLINE CVector4f();
00040 
00047     SICPPSDK_INLINE CVector4f(float in_fX, float in_fY, float in_fZ, float in_fW);
00048 
00052     SICPPSDK_INLINE CVector4f( const CVector4f& in_vector4);
00053 
00055     SICPPSDK_INLINE ~CVector4f();
00056 
00061     SICPPSDK_INLINE CVector4f & operator=( const CVector4f & in_vector4 );
00062 
00068     SICPPSDK_INLINE bool operator ==(const CVector4f & in_vector4 )const;
00069 
00075     SICPPSDK_INLINE bool operator !=(const CVector4f & in_vector4 )const;
00076 
00084     SICPPSDK_INLINE bool operator < ( const CVector4f & in_vector4 ) const;
00085 
00090     SICPPSDK_INLINE CVector4f& operator ~();
00091 
00097     SICPPSDK_INLINE CVector4f& operator +=(const CVector4f& in_vector4);
00098 
00104     SICPPSDK_INLINE CVector4f& operator -=(const CVector4f & in_vector4);
00105 
00111     SICPPSDK_INLINE CVector4f& operator *=(const CMatrix4f& in_matrix4);
00112 
00118     SICPPSDK_INLINE CVector4f& operator *=(const float& in_fAlpha);
00119 
00125     SICPPSDK_INLINE float operator[](const short& in_sIndex);
00126 
00131     SICPPSDK_INLINE CVector4f& MulByMatrix4InPlace(const CMatrix4f& in_matrix4);
00132 
00138     SICPPSDK_INLINE CVector4f& MulByMatrix4
00139     (
00140         const CVector4f& in_vector4,
00141         const CMatrix4f& in_matrix4
00142     );
00143 
00147     SICPPSDK_INLINE CVector4f& SetNull();
00148 
00152     float GetLength()const;
00153 
00157     float GetLengthSquared()const;
00158 
00162     SICPPSDK_INLINE CStatus NormalizeInPlace();
00163 
00168     SICPPSDK_INLINE CStatus Normalize(const CVector4f& in_vector4);
00169 
00174     SICPPSDK_INLINE float Dot(const CVector4f& in_vector4)const;
00175 
00181     SICPPSDK_INLINE CVector4f& Cross(const CVector4f& in_vector4A, const CVector4f& in_vector4B);
00182 
00186     CVector4f& AbsoluteInPlace();
00187 
00192     CVector4f& Absolute(const CVector4f& in_vector4);
00193 
00199     bool EpsilonEquals( const CVector4f& in_vector4, float in_fEpsilon) const;
00200 
00205     SICPPSDK_INLINE bool Equals(const CVector4f& in_vector4)const;
00206 
00212     SICPPSDK_INLINE CVector4f& ScaleAddInPlace(float in_fS,const CVector4f& in_vector4);
00213 
00220     SICPPSDK_INLINE CVector4f& ScaleAdd
00221     (
00222         float               in_fS,
00223         const CVector4f&    in_vector4A,
00224         const CVector4f&    in_vector4B
00225     );
00226 
00231     SICPPSDK_INLINE CVector4f& ScaleInPlace(float in_fAlpha);
00232 
00238     SICPPSDK_INLINE CVector4f& Scale(float in_fAlpha, const CVector4f& in_vector4);
00239 
00243     SICPPSDK_INLINE CVector4f& NegateInPlace();
00244 
00249     SICPPSDK_INLINE CVector4f& Negate(const CVector4f& in_vector4);
00250 
00255     SICPPSDK_INLINE CVector4f& SubInPlace(const CVector4f& in_vector4);
00256 
00262     SICPPSDK_INLINE CVector4f& Sub(const CVector4f& in_vector4A, const CVector4f& in_vector4B);
00263 
00268     SICPPSDK_INLINE CVector4f& AddInPlace(const CVector4f& in_vector4);
00269 
00275     SICPPSDK_INLINE CVector4f& Add(const CVector4f& in_vector4A,const CVector4f& in_vector4B);
00276 
00283     SICPPSDK_INLINE void Get( float& out_fX, float& out_fY, float& out_fZ, float& out_fW )const;
00284 
00292     SICPPSDK_INLINE CVector4f& Set(float in_fX, float in_fY, float in_fZ, float in_fW);
00293 
00297     SICPPSDK_INLINE float GetW()const;
00298 
00303     SICPPSDK_INLINE CVector4f& PutW(float in_fW);
00304 
00308     SICPPSDK_INLINE float GetZ()const;
00309 
00314     SICPPSDK_INLINE CVector4f& PutZ(float in_fZ);
00315 
00319     SICPPSDK_INLINE float GetY()const;
00320 
00325     SICPPSDK_INLINE CVector4f& PutY(float in_fY);
00326 
00330     SICPPSDK_INLINE float GetX()const;
00331 
00336     SICPPSDK_INLINE CVector4f& PutX(float in_fX);
00337 
00338 private:
00339     float m_fX,m_fY,m_fZ,m_fW;
00340 };
00341 
00342 SICPPSDK_INLINE CVector4f::CVector4f(): m_fX(0.0),m_fY(0.0),m_fZ(0.0), m_fW(0.0)
00343 {}
00344 
00345 SICPPSDK_INLINE CVector4f::CVector4f
00346 (
00347  float in_fX, float in_fY, float in_fZ, float in_fW
00348 ):m_fX(in_fX),m_fY(in_fY),m_fZ(in_fZ), m_fW(in_fW)
00349 {}
00350 
00351 SICPPSDK_INLINE CVector4f::~CVector4f()
00352 {}
00353 
00354 SICPPSDK_INLINE CVector4f::CVector4f( const CVector4f& in_vct )
00355 {
00356     in_vct.Get(m_fX,m_fY,m_fZ,m_fW);
00357 }
00358 
00359 SICPPSDK_INLINE CVector4f& CVector4f::operator=( const CVector4f & in_vct )
00360 {
00361     in_vct.Get(m_fX,m_fY,m_fZ,m_fW);
00362     return (*this);
00363 }
00364 
00365 SICPPSDK_INLINE bool CVector4f::operator ==(const CVector4f & in_vector4 )const
00366 {
00367     return Equals(in_vector4);
00368 }
00369 
00370 SICPPSDK_INLINE bool CVector4f::operator !=(const CVector4f & in_vector4 )const
00371 {
00372     return ! Equals(in_vector4);
00373 }
00374 
00375 SICPPSDK_INLINE bool CVector4f::operator < ( const CVector4f& in_vector4 ) const
00376 {
00377     if ( m_fW != in_vector4.m_fW ) return m_fW < in_vector4.m_fW;
00378     if ( m_fZ != in_vector4.m_fZ ) return m_fZ < in_vector4.m_fZ;
00379     if ( m_fY != in_vector4.m_fY ) return m_fY < in_vector4.m_fY;
00380     if ( m_fX != in_vector4.m_fX ) return m_fX < in_vector4.m_fX;
00381     return false;
00382 }
00383 
00384 SICPPSDK_INLINE CVector4f& CVector4f::operator ~()
00385 {
00386     return NegateInPlace();
00387 }
00388 
00389 SICPPSDK_INLINE CVector4f& CVector4f::operator +=(const CVector4f& in_vector4)
00390 {
00391     return AddInPlace(in_vector4);
00392 }
00393 
00394 SICPPSDK_INLINE CVector4f& CVector4f::operator -=(const CVector4f& in_vector4)
00395 {
00396     return SubInPlace(in_vector4);
00397 }
00398 
00399 SICPPSDK_INLINE CVector4f& CVector4f::operator *=(const CMatrix4f& in_matrix4)
00400 {
00401     return MulByMatrix4InPlace(in_matrix4);
00402 }
00403 
00404 SICPPSDK_INLINE CVector4f& CVector4f::operator *=(const float& in_fAlpha)
00405 {
00406     return ScaleInPlace(in_fAlpha);
00407 }
00408 
00409 SICPPSDK_INLINE CVector4f& CVector4f::MulByMatrix4InPlace
00410 (
00411     const CMatrix4f& in_matrix4
00412 )
00413 {
00414     return MulByMatrix4((*this),in_matrix4);
00415 }
00416 
00417 SICPPSDK_INLINE CVector4f& CVector4f::MulByMatrix4
00418 (
00419     const CVector4f& in_vector4,
00420     const CMatrix4f& in_matrix4
00421 )
00422 {
00423     float l_fX, l_fY, l_fZ, l_fW;
00424 
00425     l_fX =  in_vector4.GetX() * in_matrix4.GetValue( 0, 0 ) +
00426             in_vector4.GetY() * in_matrix4.GetValue( 1, 0 ) +
00427             in_vector4.GetZ() * in_matrix4.GetValue( 2, 0 ) +
00428             in_vector4.GetW() * in_matrix4.GetValue( 3, 0 );
00429     l_fY =  in_vector4.GetX() * in_matrix4.GetValue( 0, 1 ) +
00430             in_vector4.GetY() * in_matrix4.GetValue( 1, 1 ) +
00431             in_vector4.GetZ() * in_matrix4.GetValue( 2, 1 ) +
00432             in_vector4.GetW() * in_matrix4.GetValue( 3, 1 );
00433     l_fZ =  in_vector4.GetX() * in_matrix4.GetValue( 0, 2 ) +
00434             in_vector4.GetY() * in_matrix4.GetValue( 1, 2 ) +
00435             in_vector4.GetZ() * in_matrix4.GetValue( 2, 2 ) +
00436             in_vector4.GetW() * in_matrix4.GetValue( 3, 2 );
00437     l_fW =  in_vector4.GetX() * in_matrix4.GetValue( 0, 3 ) +
00438             in_vector4.GetY() * in_matrix4.GetValue( 1, 3 ) +
00439             in_vector4.GetZ() * in_matrix4.GetValue( 2, 3 ) +
00440             in_vector4.GetW() * in_matrix4.GetValue( 3, 3 );
00441 
00442     return Set(l_fX, l_fY, l_fZ, l_fW);
00443 }
00444 
00445 SICPPSDK_INLINE CVector4f& CVector4f::SetNull()
00446 {
00447     m_fX = m_fY = m_fZ = m_fW = 0.0;
00448     return (*this);
00449 }
00450 
00451 SICPPSDK_INLINE float CVector4f::Dot(const CVector4f& in_vector4)const
00452 {
00453 
00454     return ( m_fX*in_vector4.GetX() + m_fY*in_vector4.GetY() +
00455             m_fZ*in_vector4.GetZ() + m_fW*in_vector4.GetW());
00456 }
00457 
00458 SICPPSDK_INLINE bool CVector4f::Equals(const CVector4f& in_vector4)const
00459 {
00460     return (this == &in_vector4) ? true :
00461             ( ( m_fX == in_vector4.GetX() ) &&
00462               ( m_fY == in_vector4.GetY() ) &&
00463               ( m_fZ == in_vector4.GetZ() ) &&
00464               ( m_fW == in_vector4.GetW() ) );
00465 }
00466 
00467 SICPPSDK_INLINE CVector4f& CVector4f::ScaleAddInPlace
00468 (
00469     float in_fScalingFactor,
00470     const CVector4f& in_vector4
00471 )
00472 {
00473     ScaleInPlace(in_fScalingFactor);
00474     return AddInPlace(in_vector4);
00475 }
00476 
00477 SICPPSDK_INLINE CVector4f& CVector4f::ScaleAdd
00478 (
00479     const float in_fScalingFactor,
00480     const CVector4f& in_vector4A,
00481     const CVector4f& in_vector4B
00482 )
00483 {
00484     Scale(in_fScalingFactor, in_vector4A);
00485     return AddInPlace(in_vector4B);
00486 }
00487 
00488 SICPPSDK_INLINE CVector4f& CVector4f::ScaleInPlace(float in_fScalingFactor)
00489 {
00490     m_fX *= in_fScalingFactor;
00491     m_fY *= in_fScalingFactor;
00492     m_fZ *= in_fScalingFactor;
00493     m_fW *= in_fScalingFactor;
00494     return (*this);
00495 }
00496 
00497 SICPPSDK_INLINE CVector4f& CVector4f::Scale
00498 (
00499  float in_fScalingFactor,
00500  const CVector4f& in_vector4
00501 )
00502 {
00503     m_fX = in_vector4.GetX() * in_fScalingFactor;
00504     m_fY = in_vector4.GetY() * in_fScalingFactor;
00505     m_fZ = in_vector4.GetZ() * in_fScalingFactor;
00506     m_fW = in_vector4.GetW() * in_fScalingFactor;
00507     return (*this);
00508 }
00509 
00510 SICPPSDK_INLINE CVector4f& CVector4f::NegateInPlace()
00511 {
00512     m_fX = -m_fX;
00513     m_fY = -m_fY;
00514     m_fZ = -m_fZ;
00515     m_fW = -m_fW;
00516     return (*this);
00517 }
00518 
00519 SICPPSDK_INLINE CVector4f& CVector4f::Negate(const CVector4f& in_vector4 )
00520 {
00521     m_fX = -in_vector4.GetX();
00522     m_fY = -in_vector4.GetY();
00523     m_fZ = -in_vector4.GetZ();
00524     m_fW = -in_vector4.GetW();
00525     return (*this);
00526 }
00527 
00528 SICPPSDK_INLINE CVector4f& CVector4f::SubInPlace(const CVector4f& in_vector4)
00529 {
00530     m_fX -= in_vector4.GetX();
00531     m_fY -= in_vector4.GetY();
00532     m_fZ -= in_vector4.GetZ();
00533     m_fW -= in_vector4.GetW();
00534     return (*this);
00535 }
00536 
00537 SICPPSDK_INLINE CVector4f& CVector4f::Sub
00538 (
00539     const CVector4f& in_vector4A,
00540     const CVector4f& in_vector4B
00541 )
00542 {
00543     m_fX = in_vector4A.GetX() - in_vector4B.GetX();
00544     m_fY = in_vector4A.GetY() - in_vector4B.GetY();
00545     m_fZ = in_vector4A.GetZ() - in_vector4B.GetZ();
00546     m_fW = in_vector4A.GetW() - in_vector4B.GetW();
00547     return (*this);
00548 }
00549 
00550 SICPPSDK_INLINE CVector4f& CVector4f::AddInPlace(const CVector4f& in_vector4)
00551 {
00552     m_fX += in_vector4.GetX();
00553     m_fY += in_vector4.GetY();
00554     m_fZ += in_vector4.GetZ();
00555     m_fW += in_vector4.GetW();
00556     return (*this);
00557 }
00558 
00559 SICPPSDK_INLINE CVector4f& CVector4f::Add
00560 (
00561     const CVector4f& in_vector4A,
00562     const CVector4f& in_vector4B
00563 )
00564 {
00565     m_fX = in_vector4A.GetX() + in_vector4B.GetX();
00566     m_fY = in_vector4A.GetY() + in_vector4B.GetY();
00567     m_fZ = in_vector4A.GetZ() + in_vector4B.GetZ();
00568     m_fW = in_vector4A.GetW() + in_vector4B.GetW();
00569     return (*this);
00570 }
00571 
00572 SICPPSDK_INLINE void CVector4f::Get
00573 (
00574     float& out_rdX,
00575     float& out_rdY,
00576     float& out_rdZ,
00577     float& out_rdW
00578 )const
00579 {
00580     out_rdX = m_fX;
00581     out_rdY = m_fY;
00582     out_rdZ = m_fZ;
00583     out_rdW = m_fW;
00584 }
00585 
00586 SICPPSDK_INLINE CVector4f& CVector4f::Set
00587 (
00588     float in_fX,
00589     float in_fY,
00590     float in_fZ,
00591     float in_fW
00592 )
00593 {
00594     m_fX = in_fX;
00595     m_fY = in_fY;
00596     m_fZ = in_fZ;
00597     m_fW = in_fW;
00598     return (*this);
00599 }
00600 
00601 SICPPSDK_INLINE float CVector4f::GetW()const
00602 {
00603     return m_fW;
00604 }
00605 
00606 SICPPSDK_INLINE CVector4f&  CVector4f::PutW(float in_fW)
00607 {
00608     m_fW = in_fW;
00609     return (*this);
00610 }
00611 
00612 SICPPSDK_INLINE float CVector4f::GetZ()const
00613 {
00614     return m_fZ;
00615 }
00616 
00617 SICPPSDK_INLINE CVector4f&  CVector4f::PutZ(float in_fZ)
00618 {
00619     m_fZ = in_fZ;
00620     return (*this);
00621 }
00622 
00623 SICPPSDK_INLINE float CVector4f::GetY()const
00624 {
00625     return m_fY;
00626 }
00627 
00628 SICPPSDK_INLINE CVector4f& CVector4f::PutY(float in_fY)
00629 {
00630     m_fY = in_fY;
00631     return (*this);
00632 }
00633 
00634 SICPPSDK_INLINE float CVector4f::GetX()const
00635 {
00636     return m_fX;
00637 }
00638 
00639 SICPPSDK_INLINE CVector4f& CVector4f::PutX(float in_fX)
00640 {
00641     m_fX = in_fX;
00642     return (*this);
00643 }
00644 
00645 SICPPSDK_INLINE float CVector4f::operator[](const short& in_sIndex)
00646 {
00647     assert(in_sIndex >= 0 && in_sIndex < 4);
00648     switch(in_sIndex)
00649     {
00650         case 0:
00651             return m_fX;
00652             break;
00653         case 1:
00654             return m_fY;
00655             break;
00656         case 2:
00657             return m_fZ;
00658             break;
00659         case 3:
00660             return m_fW;
00661             break;
00662     }
00663     return FLT_MAX;
00664 }
00665 
00666 SICPPSDK_INLINE CVector4f& CVector4f::AbsoluteInPlace()
00667 {
00668     ::fabs(m_fX);
00669     ::fabs(m_fY);
00670     ::fabs(m_fZ);
00671     ::fabs(m_fW);
00672     return (*this);
00673 }
00674 
00675 SICPPSDK_INLINE CVector4f& CVector4f::Absolute(const CVector4f& in_vector4)
00676 {
00677     float dX, dY, dZ, dW;
00678     in_vector4.Get(dX, dY, dZ, dW);
00679     m_fX = ::fabs(dX);
00680     m_fY = ::fabs(dY);
00681     m_fZ = ::fabs(dZ);
00682     m_fW = ::fabs(dW);
00683 
00684     return (*this);
00685 }
00686 SICPPSDK_INLINE bool CVector4f::EpsilonEquals
00687 (
00688     const CVector4f& in_vector4,
00689     float in_fEpsilon
00690 )const
00691 {
00692     return (this == &in_vector4) ? true :
00693         (fabs( m_fX - in_vector4.GetX() ) < ::fabs(in_fEpsilon) &&
00694          fabs( m_fY - in_vector4.GetY() ) < ::fabs(in_fEpsilon) &&
00695          fabs( m_fZ - in_vector4.GetZ() ) < ::fabs(in_fEpsilon) &&
00696          fabs( m_fW - in_vector4.GetW() ) < ::fabs(in_fEpsilon));
00697 }
00698 
00699 SICPPSDK_INLINE float CVector4f::GetLength()const
00700 {
00701     return sqrt( GetLengthSquared() );
00702 }
00703 
00704 SICPPSDK_INLINE float CVector4f::GetLengthSquared()const
00705 {
00706      return(m_fX*m_fX + m_fY*m_fY + m_fZ*m_fZ  + m_fW*m_fW);
00707 }
00708 
00709 SICPPSDK_INLINE CStatus CVector4f::NormalizeInPlace()
00710 {
00711     float rLen = GetLength();
00712 
00713     if ( rLen > MicroEPS )
00714     {
00715         m_fX /= rLen ;
00716         m_fY /= rLen ;
00717         m_fZ /= rLen ;
00718         m_fW /= rLen ;
00719         return CStatus::OK;
00720     }
00721 
00722     return CStatus::Fail;
00723 }
00724 
00725 SICPPSDK_INLINE CStatus CVector4f::Normalize(const CVector4f& in_vector4)
00726 {
00727     float rLen = in_vector4.GetLength();
00728 
00729     if ( rLen > MicroEPS )
00730     {
00731         m_fX = in_vector4.GetX() / rLen ;
00732         m_fY = in_vector4.GetY() / rLen ;
00733         m_fZ = in_vector4.GetZ() / rLen ;
00734         m_fW = in_vector4.GetW() / rLen ;
00735         return CStatus::OK;
00736     }
00737 
00738     return CStatus::Fail;
00739 }
00740 
00741 };
00742 };
00743 
00744 #endif // __XSIVECTOR4_H__