"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSMathLib/Src/Vector/LSMVector3Base.h

00001 
00016 #ifndef __LSM_VECTOR3BASE_H__
00017 #define __LSM_VECTOR3BASE_H__
00018 
00019 #include "../LSMMathLib.h"
00020 
00021 namespace lsm {
00022 
00029         template <typename _tType, typename _tInher>
00030         class CVector3Base {
00031                 // All is public.  This class has no secrets.
00032         public :
00033                 // == Various constructors.
00034                 LSE_CALLCTOR                                                    CVector3Base() {
00035                 }
00036                 LSE_CALLCTOR                                                    CVector3Base( const _tInher &_v3bOther ) :
00037                         x( _v3bOther.x ),
00038                         y( _v3bOther.y ),
00039                         z( _v3bOther.z ) {
00040                 }
00041                 LSE_CALLCTOR                                                    CVector3Base( _tType _fX, _tType _fY, _tType _fZ ) :
00042                         x( _fX ),
00043                         y( _fY ),
00044                         z( _fZ ) {
00045                 }
00046                 LSE_CALLCTOR                                                    CVector3Base( _tType * _pfValues ) :
00047                         x( _pfValues[0] ),
00048                         y( _pfValues[1] ),
00049                         z( _pfValues[2] ) {
00050                 }
00051 
00052                 // == Operators.
00059                 _tType LSE_FCALL                                                operator [] ( LSUINT32 _ui32Index ) const {
00060                         return reinterpret_cast<const _tType *>(this)[_ui32Index];
00061                 }
00062 
00069                 _tType & LSE_FCALL                                              operator [] ( LSUINT32 _ui32Index ) {
00070                         return reinterpret_cast<_tType *>(this)[_ui32Index];
00071                 }
00072 
00079                 _tInher & LSE_FCALL                                             operator = ( const _tInher &_v3bOther ) {
00080                         x = _v3bOther.x;
00081                         y = _v3bOther.y;
00082                         z = _v3bOther.z;
00083                         return (*static_cast<_tInher *>(this));
00084                 }
00085 
00092                 LSBOOL LSE_FCALL                                                operator == ( const _tInher &_v3bOther ) const {
00093                         return x == _v3bOther.x && y == _v3bOther.y && z == _v3bOther.z;
00094                 }
00095 
00102                 LSBOOL LSE_FCALL                                                operator != ( const _tInher &_v3bOther ) const {
00103                         return x != _v3bOther.x || y != _v3bOther.y || z != _v3bOther.z;
00104                 }
00105 
00111                 _tInher LSE_FCALL                                               operator - () const {
00112                         return _tInher( -x, -y, -z );
00113                 }
00114 
00121                 _tInher LSE_FCALL                                               operator + ( const _tInher &_v3bOther ) const {
00122                         return _tInher( x + _v3bOther.x, y + _v3bOther.y, z + _v3bOther.z );
00123                 }
00124 
00131                 _tInher LSE_FCALL                                               operator - ( const _tInher &_v3bOther ) const {
00132                         return _tInher( x - _v3bOther.x, y - _v3bOther.y, z - _v3bOther.z );
00133                 }
00134 
00141                 _tInher LSE_FCALL                                               operator * ( _tType _tValue ) const {
00142                         return _tInher( x * _tValue, y * _tValue, z * _tValue );
00143                 }
00144 
00151                 _tInher LSE_FCALL                                               operator / ( _tType _tValue ) const {
00152                         return (*static_cast<const _tInher *>(this)) * (_tType( 1 ) / _tValue);
00153                 }
00154 
00161                 _tInher & LSE_FCALL                                             operator += ( const _tInher &_v3bOther ) {
00162                         x += _v3bOther.x;
00163                         y += _v3bOther.y;
00164                         z += _v3bOther.z;
00165                         return (*static_cast<_tInher *>(this));
00166                 }
00167 
00174                 _tInher & LSE_FCALL                                             operator += ( _tType _tValue ) {
00175                         x += _tValue;
00176                         y += _tValue;
00177                         z += _tValue;
00178                         return (*static_cast<_tInher *>(this));
00179                 }
00180 
00187                 _tInher & LSE_FCALL                                             operator -= ( const _tInher &_v3bOther ) {
00188                         x -= _v3bOther.x;
00189                         y -= _v3bOther.y;
00190                         z -= _v3bOther.z;
00191                         return (*static_cast<_tInher *>(this));
00192                 }
00193 
00200                 _tInher & LSE_FCALL                                             operator -= ( _tType _tValue ) {
00201                         x -= _tValue;
00202                         y -= _tValue;
00203                         z -= _tValue;
00204                         return (*static_cast<_tInher *>(this));
00205                 }
00206 
00213                 _tInher & LSE_FCALL                                             operator *= ( _tType _tValue ) {
00214                         x *= _tValue;
00215                         y *= _tValue;
00216                         z *= _tValue;
00217                         return (*static_cast<_tInher *>(this));
00218                 }
00219 
00226                 _tInher & LSE_FCALL                                             operator /= ( _tType _tValue ) {
00227                         return (*static_cast<_tInher *>(this)) *= (_tType( 1 ) / _tValue);
00228                 }
00229 
00237                 _tType LSE_FCALL                                                operator * ( const _tInher &_v3bOther ) const {
00238                         return x * _v3bOther.x + y * _v3bOther.y + z * _v3bOther.z;
00239                 }
00240 
00248                 _tInher LSE_FCALL                                               operator % ( const _tInher &_v3bOther ) const {
00249                         return _tInher( y * _v3bOther.z - z * _v3bOther.y,
00250                                 z * _v3bOther.x - x * _v3bOther.z,
00251                                 x * _v3bOther.y - y * _v3bOther.x );
00252                 }
00253 
00254 
00255                 // == Functions.
00263                 LSVOID LSE_FCALL                                                Set( _tType _fX, _tType _fY, _tType _fZ ) {
00264                         x = _fX;
00265                         y = _fY;
00266                         z = _fZ;
00267                 }
00268 
00272                 LSVOID LSE_FCALL                                                Clear() {
00273                         x = y = z = _tType( 0 );
00274                 }
00275 
00279                 LSVOID LSE_FCALL                                                Invert() {
00280                         x = -x;
00281                         y = -y;
00282                         z = -z;
00283                 }
00284 
00290                 _tType LSE_FCALL                                                Len() const {
00291                         return static_cast<_tType>(::sqrt( static_cast<LSDOUBLE>(x * x + y * y + z * z) ));
00292                 }
00293 
00299                 _tType LSE_FCALL                                                LenSq() const {
00300                         return x * x + y * y + z * z;
00301                 }
00302 
00308                 LSVOID LSE_FCALL                                                Normalize() {
00309                         _tType fInvLen = static_cast<_tType>(1.0 / ::sqrt( static_cast<LSDOUBLE>(x * x + y * y + z * z) ));
00310                         x *= fInvLen;
00311                         y *= fInvLen;
00312                         z *= fInvLen;
00313                 }
00314 
00322                 _tType LSE_FCALL                                                Dot( const _tInher &_v3bOther ) const {
00323                         return x * _v3bOther.x + y * _v3bOther.y + z * _v3bOther.z;
00324                 }
00325 
00333                 _tInher LSE_FCALL                                               Cross( const _tInher &_v3bOther ) const {
00334                         return _tInher( y * _v3bOther.z - z * _v3bOther.y,
00335                                 z * _v3bOther.x - x * _v3bOther.z,
00336                                 x * _v3bOther.y - y * _v3bOther.x );
00337                 }
00338 
00347                 static _tType LSE_FCALL                                 DotProduct( const _tInher &_v3bLeft, const _tInher &_v3bRight ) {
00348                         return _v3bLeft.x * _v3bRight.x + _v3bLeft.y * _v3bRight.y + _v3bLeft.z * _v3bRight.z;
00349                 }
00350 
00359                 static _tInher LSE_FCALL                                CrossProduct( const _tInher &_v3bLeft, const _tInher &_v3bRight ) {
00360                         return _tInher( _v3bLeft.y * _v3bRight.z - _v3bLeft.z * _v3bRight.y,
00361                                 _v3bLeft.z * _v3bRight.x - _v3bLeft.x * _v3bRight.z,
00362                                 _v3bLeft.x * _v3bRight.y - _v3bLeft.y * _v3bRight.x );
00363                 }
00364 
00373                 static _tInher LSE_FCALL                                Lerp( const _tInher &_v3bLeft, const _tInher &_v3bRight, _tType _fFrac ) {
00374                         return ((_v3bRight - _v3bLeft) * _fFrac) + _v3bLeft;
00375                 }
00376 
00387                 static _tInher LSE_FCALL                                Hermite( const _tInher &_v3bLeft, const _tInher &_v3bT0,
00388                         const _tInher &_v3bRight, const _tInher &_v3bT1,
00389                         _tType _fFrac ) {
00390                         _tType fS2      = _fFrac * _fFrac;
00391                         _tType fS3      = fS2 * _fFrac;
00392                         _tType f2s2     = static_cast<_tType>(2.0) * fS2;
00393                         _tType f2s3     = static_cast<_tType>(2.0) * fS3;
00394                         _tType f3s2     = static_cast<_tType>(3.0) * fS2;
00395 
00396                         return (_v3bLeft * (f2s3 - f3s2 + LSM_ONE)) +
00397                                 (_v3bRight * (-f2s3 + f3s2)) +
00398                                 (_v3bT0 * (fS3 - f2s2 + _fFrac)) +
00399                                 (_v3bT1 * (fS3 - fS2));
00400                 }
00401 
00412                 static _tInher LSE_FCALL                                CatmullRom( const _tInher &_v3bV0, const _tInher &_v3bV1,
00413                         const _tInher &_v3bV2, const _tInher &_v3bV3,
00414                         _tType _fFrac ) {
00415                         _tType fS2      = _fFrac * _fFrac;
00416                         return ((_v3bV1 * static_cast<_tType>(2.0)) +
00417                                 (-_v3bV0 + _v3bV2) * _fFrac +
00418                                 (_v3bV0 * static_cast<_tType>(2.0) - _v3bV1 * static_cast<_tType>(5.0) + _v3bV2 * static_cast<_tType>(4.0) - _v3bV3) * fS2 +
00419                                 (-_v3bV0 + _v3bV1 * static_cast<_tType>(3.0) - _v3bV2 * static_cast<_tType>(3.0) + _v3bV3) * fS2 * _fFrac) * LSM_HALF;
00420                 }
00421 
00422 
00423                 // == Members.
00424 #pragma pack( push, 1 )
00425 
00428                 _tType                                                                  x;
00429 
00433                 _tType                                                                  y;
00434 
00438                 _tType                                                                  z;
00439 #pragma pack( pop )
00440         };
00441 
00442 }       // namespace lsm
00443 
00444 #endif  // __LSM_VECTOR3BASE_H__
00445 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator