Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreVector4.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #ifndef __Vector4_H__
    00026 #define __Vector4_H__
    00027
    00028 #include "OgrePrerequisites.h"
    00029 #include "OgreVector3.h"
    00030
    00031 namespace Ogre
    00032 {
    00033
    00036     class _OgreExport Vector4
    00037     {
    00038     public:
    00039         union {
    00040             struct {
    00041                 Real x, y, z, w;
    00042             };
    00043             Real val[4];
    00044         };
    00045
    00046     public:
    00047         inline Vector4()
    00048         {
    00049         }
    00050
    00051         inline Vector4( Real fX, Real fY, Real fZ, Real fW )
    00052             : x( fX ), y( fY ), z( fZ ), w( fW)
    00053         {
    00054         }
    00055
    00056         inline Vector4( Real afCoordinate[4] )
    00057             : x( afCoordinate[0] ),
    00058               y( afCoordinate[1] ),
    00059               z( afCoordinate[2] ),
    00060               w (afCoordinate[3] )
    00061         {
    00062         }
    00063
    00064         inline Vector4( int afCoordinate[4] )
    00065         {
    00066             x = (Real)afCoordinate[0];
    00067             y = (Real)afCoordinate[1];
    00068             z = (Real)afCoordinate[2];
    00069             w = (Real)afCoordinate[3];
    00070         }
    00071
    00072         inline Vector4( const Real* const r )
    00073             : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] )
    00074         {
    00075         }
    00076
    00077         inline Vector4( const Vector4& rkVector )
    00078             : x( rkVector.x ), y( rkVector.y ), z( rkVector.z ), w (rkVector.w)
    00079         {
    00080         }
    00081
    00082         inline Real operator [] ( size_t i ) const
    00083         {
    00084             assert( i < 4 );
    00085
    00086             return *(&x+i);
    00087         }
    00088
    00089         inline Real& operator [] ( size_t i )
    00090         {
    00091             assert( i < 4 );
    00092
    00093             return *(&x+i);
    00094         }
    00095
    00100         inline Vector4& operator = ( const Vector4& rkVector )
    00101         {
    00102             x = rkVector.x;
    00103             y = rkVector.y;
    00104             z = rkVector.z;
    00105             w = rkVector.w;
    00106
    00107             return *this;
    00108         }
    00109
    00110         inline bool operator == ( const Vector4& rkVector ) const
    00111         {
    00112             return ( x == rkVector.x &&
    00113                 y == rkVector.y &&
    00114                 z == rkVector.z &&
    00115                 w == rkVector.w );
    00116         }
    00117
    00118         inline bool operator != ( const Vector4& rkVector ) const
    00119         {
    00120             return ( x != rkVector.x ||
    00121                 y != rkVector.y ||
    00122                 z != rkVector.z ||
    00123                 w != rkVector.w );
    00124         }
    00125
    00126         inline Vector4& operator = (const Vector3& rhs)
    00127         {
    00128             x = rhs.x;
    00129             y = rhs.y;
    00130             z = rhs.z;
    00131             w = 1.0f;
    00132             return *this;
    00133         }
    00134
    00135         // arithmetic operations
    00136         inline Vector4 operator + ( const Vector4& rkVector ) const
    00137         {
    00138             Vector4 kSum;
    00139
    00140             kSum.x = x + rkVector.x;
    00141             kSum.y = y + rkVector.y;
    00142             kSum.z = z + rkVector.z;
    00143             kSum.w = w + rkVector.w;
    00144
    00145             return kSum;
    00146         }
    00147
    00148         inline Vector4 operator - ( const Vector4& rkVector ) const
    00149         {
    00150             Vector4 kDiff;
    00151
    00152             kDiff.x = x - rkVector.x;
    00153             kDiff.y = y - rkVector.y;
    00154             kDiff.z = z - rkVector.z;
    00155             kDiff.w = w - rkVector.w;
    00156
    00157             return kDiff;
    00158         }
    00159
    00160         inline Vector4 operator * ( Real fScalar ) const
    00161         {
    00162             Vector4 kProd;
    00163
    00164             kProd.x = fScalar*x;
    00165             kProd.y = fScalar*y;
    00166             kProd.z = fScalar*z;
    00167             kProd.w = fScalar*w;
    00168
    00169             return kProd;
    00170         }
    00171
    00172         inline Vector4 operator * ( const Vector4& rhs) const
    00173         {
    00174             Vector4 kProd;
    00175
    00176             kProd.x = rhs.x * x;
    00177             kProd.y = rhs.y * y;
    00178             kProd.z = rhs.z * z;
    00179             kProd.w = rhs.w * w;
    00180
    00181             return kProd;
    00182         }
    00183
    00184         inline Vector4 operator / ( Real fScalar ) const
    00185         {
    00186             assert( fScalar != 0.0 );
    00187
    00188             Vector4 kDiv;
    00189
    00190             Real fInv = 1.0 / fScalar;
    00191             kDiv.x = x * fInv;
    00192             kDiv.y = y * fInv;
    00193             kDiv.z = z * fInv;
    00194             kDiv.w = w * fInv;
    00195
    00196             return kDiv;
    00197         }
    00198
    00199         inline Vector4 operator / ( const Vector4& rhs) const
    00200         {
    00201             Vector4 kDiv;
    00202
    00203             kDiv.x = x / rhs.x;
    00204             kDiv.y = y / rhs.y;
    00205             kDiv.z = z / rhs.z;
    00206             kDiv.w = w / rhs.w;
    00207
    00208             return kDiv;
    00209         }
    00210
    00211
    00212         inline Vector4 operator - () const
    00213         {
    00214             Vector4 kNeg;
    00215
    00216             kNeg.x = -x;
    00217             kNeg.y = -y;
    00218             kNeg.z = -z;
    00219             kNeg.w = -w;
    00220
    00221             return kNeg;
    00222         }
    00223
    00224         inline friend Vector4 operator * ( Real fScalar, const Vector4& rkVector )
    00225         {
    00226             Vector4 kProd;
    00227
    00228             kProd.x = fScalar * rkVector.x;
    00229             kProd.y = fScalar * rkVector.y;
    00230             kProd.z = fScalar * rkVector.z;
    00231             kProd.w = fScalar * rkVector.w;
    00232
    00233             return kProd;
    00234         }
    00235
    00236         // arithmetic updates
    00237         inline Vector4& operator += ( const Vector4& rkVector )
    00238         {
    00239             x += rkVector.x;
    00240             y += rkVector.y;
    00241             z += rkVector.z;
    00242             w += rkVector.w;
    00243
    00244             return *this;
    00245         }
    00246
    00247         inline Vector4& operator -= ( const Vector4& rkVector )
    00248         {
    00249             x -= rkVector.x;
    00250             y -= rkVector.y;
    00251             z -= rkVector.z;
    00252             w -= rkVector.w;
    00253
    00254             return *this;
    00255         }
    00256
    00257         inline Vector4& operator *= ( Real fScalar )
    00258         {
    00259             x *= fScalar;
    00260             y *= fScalar;
    00261             z *= fScalar;
    00262             w *= fScalar;
    00263             return *this;
    00264         }
    00265
    00266         inline Vector4& operator *= ( const Vector4& rkVector )
    00267         {
    00268             x *= rkVector.x;
    00269             y *= rkVector.y;
    00270             z *= rkVector.z;
    00271             w *= rkVector.w;
    00272
    00273             return *this;
    00274         }
    00275
    00276         inline Vector4& operator /= ( Real fScalar )
    00277         {
    00278             assert( fScalar != 0.0 );
    00279
    00280             Real fInv = 1.0 / fScalar;
    00281
    00282             x *= fInv;
    00283             y *= fInv;
    00284             z *= fInv;
    00285             w *= fInv;
    00286
    00287             return *this;
    00288         }
    00289
    00290         inline Vector4& operator /= ( const Vector4& rkVector )
    00291         {
    00292             x /= rkVector.x;
    00293             y /= rkVector.y;
    00294             z /= rkVector.z;
    00295             w /= rkVector.w;
    00296
    00297             return *this;
    00298         }
    00299
    00307         inline Real dotProduct(const Vector4& vec) const
    00308         {
    00309             return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
    00310         }
    00313         inline _OgreExport friend std::ostream& operator <<
    00314             ( std::ostream& o, const Vector4& v )
    00315         {
    00316             o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
    00317             return o;
    00318         }
    00319     };
    00320
    00321 }
    00322 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:51 2004