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