Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class 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 (c) 2000-2006 Torus Knot Software Ltd
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 You may alternatively use this source under the terms of a specific version of
00025 the OGRE Unrestricted License provided you have obtained such a license from
00026 Torus Knot Software Ltd.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef __Vector4_H__
00030 #define __Vector4_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 #include "OgreVector3.h"
00034 
00035 namespace Ogre
00036 {
00037 
00040     class _OgreExport Vector4
00041     {
00042     public:
00043         Real x, y, z, w;
00044 
00045     public:
00046         inline Vector4()
00047         {
00048         }
00049 
00050         inline Vector4( const Real fX, const Real fY, const Real fZ, const Real fW )
00051             : x( fX ), y( fY ), z( fZ ), w( fW)
00052         {
00053         }
00054 
00055         inline explicit Vector4( const Real afCoordinate[4] )
00056             : x( afCoordinate[0] ),
00057               y( afCoordinate[1] ),
00058               z( afCoordinate[2] ),
00059               w( afCoordinate[3] )
00060         {
00061         }
00062 
00063         inline explicit Vector4( const int afCoordinate[4] )
00064         {
00065             x = (Real)afCoordinate[0];
00066             y = (Real)afCoordinate[1];
00067             z = (Real)afCoordinate[2];
00068             w = (Real)afCoordinate[3];
00069         }
00070 
00071         inline explicit Vector4( Real* const r )
00072             : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] )
00073         {
00074         }
00075 
00076         inline explicit Vector4( const Real scaler )
00077             : x( scaler )
00078             , y( scaler )
00079             , z( scaler )
00080             , w( scaler )
00081         {
00082         }
00083 
00084         inline explicit Vector4(const Vector3& rhs)
00085             : x(rhs.x), y(rhs.y), z(rhs.z), w(1.0f)
00086         {
00087         }
00088 
00089         inline Vector4( const Vector4& rkVector )
00090             : x( rkVector.x ), y( rkVector.y ), z( rkVector.z ), w (rkVector.w)
00091         {
00092         }
00093 
00094         inline Real operator [] ( const size_t i ) const
00095         {
00096             assert( i < 4 );
00097 
00098             return *(&x+i);
00099         }
00100 
00101         inline Real& operator [] ( const size_t i )
00102         {
00103             assert( i < 4 );
00104 
00105             return *(&x+i);
00106         }
00107 
00109         inline Real* ptr()
00110         {
00111             return &x;
00112         }
00114         inline const Real* ptr() const
00115         {
00116             return &x;
00117         }
00118 
00123         inline Vector4& operator = ( const Vector4& rkVector )
00124         {
00125             x = rkVector.x;
00126             y = rkVector.y;
00127             z = rkVector.z;
00128             w = rkVector.w;
00129 
00130             return *this;
00131         }
00132 
00133         inline Vector4& operator = ( const Real fScalar)
00134         {
00135             x = fScalar;
00136             y = fScalar;
00137             z = fScalar;
00138             w = fScalar;
00139             return *this;
00140         }
00141 
00142         inline bool operator == ( const Vector4& rkVector ) const
00143         {
00144             return ( x == rkVector.x &&
00145                 y == rkVector.y &&
00146                 z == rkVector.z &&
00147                 w == rkVector.w );
00148         }
00149 
00150         inline bool operator != ( const Vector4& rkVector ) const
00151         {
00152             return ( x != rkVector.x ||
00153                 y != rkVector.y ||
00154                 z != rkVector.z ||
00155                 w != rkVector.w );
00156         }
00157 
00158         inline Vector4& operator = (const Vector3& rhs)
00159         {
00160             x = rhs.x;
00161             y = rhs.y;
00162             z = rhs.z;
00163             w = 1.0f;
00164             return *this;
00165         }
00166 
00167         // arithmetic operations
00168         inline Vector4 operator + ( const Vector4& rkVector ) const
00169         {
00170             return Vector4(
00171                 x + rkVector.x,
00172                 y + rkVector.y,
00173                 z + rkVector.z,
00174                 w + rkVector.w);
00175         }
00176 
00177         inline Vector4 operator - ( const Vector4& rkVector ) const
00178         {
00179             return Vector4(
00180                 x - rkVector.x,
00181                 y - rkVector.y,
00182                 z - rkVector.z,
00183                 w - rkVector.w);
00184         }
00185 
00186         inline Vector4 operator * ( const Real fScalar ) const
00187         {
00188             return Vector4(
00189                 x * fScalar,
00190                 y * fScalar,
00191                 z * fScalar,
00192                 w * fScalar);
00193         }
00194 
00195         inline Vector4 operator * ( const Vector4& rhs) const
00196         {
00197             return Vector4(
00198                 rhs.x * x,
00199                 rhs.y * y,
00200                 rhs.z * z,
00201                 rhs.w * w);
00202         }
00203 
00204         inline Vector4 operator / ( const Real fScalar ) const
00205         {
00206             assert( fScalar != 0.0 );
00207 
00208             Real fInv = 1.0 / fScalar;
00209 
00210             return Vector4(
00211                 x * fInv,
00212                 y * fInv,
00213                 z * fInv,
00214                 w * fInv);
00215         }
00216 
00217         inline Vector4 operator / ( const Vector4& rhs) const
00218         {
00219             return Vector4(
00220                 x / rhs.x,
00221                 y / rhs.y,
00222                 z / rhs.z,
00223                 w / rhs.w);
00224         }
00225 
00226         inline const Vector4& operator + () const
00227         {
00228             return *this;
00229         }
00230 
00231         inline Vector4 operator - () const
00232         {
00233             return Vector4(-x, -y, -z, -w);
00234         }
00235 
00236         inline friend Vector4 operator * ( const Real fScalar, const Vector4& rkVector )
00237         {
00238             return Vector4(
00239                 fScalar * rkVector.x,
00240                 fScalar * rkVector.y,
00241                 fScalar * rkVector.z,
00242                 fScalar * rkVector.w);
00243         }
00244 
00245         inline friend Vector4 operator / ( const Real fScalar, const Vector4& rkVector )
00246         {
00247             return Vector4(
00248                 fScalar / rkVector.x,
00249                 fScalar / rkVector.y,
00250                 fScalar / rkVector.z,
00251                 fScalar / rkVector.w);
00252         }
00253 
00254         inline friend Vector4 operator + (const Vector4& lhs, const Real rhs)
00255         {
00256             return Vector4(
00257                 lhs.x + rhs,
00258                 lhs.y + rhs,
00259                 lhs.z + rhs,
00260                 lhs.w + rhs);
00261         }
00262 
00263         inline friend Vector4 operator + (const Real lhs, const Vector4& rhs)
00264         {
00265             return Vector4(
00266                 lhs + rhs.x,
00267                 lhs + rhs.y,
00268                 lhs + rhs.z,
00269                 lhs + rhs.w);
00270         }
00271 
00272         inline friend Vector4 operator - (const Vector4& lhs, Real rhs)
00273         {
00274             return Vector4(
00275                 lhs.x - rhs,
00276                 lhs.y - rhs,
00277                 lhs.z - rhs,
00278                 lhs.w - rhs);
00279         }
00280 
00281         inline friend Vector4 operator - (const Real lhs, const Vector4& rhs)
00282         {
00283             return Vector4(
00284                 lhs - rhs.x,
00285                 lhs - rhs.y,
00286                 lhs - rhs.z,
00287                 lhs - rhs.w);
00288         }
00289 
00290         // arithmetic updates
00291         inline Vector4& operator += ( const Vector4& rkVector )
00292         {
00293             x += rkVector.x;
00294             y += rkVector.y;
00295             z += rkVector.z;
00296             w += rkVector.w;
00297 
00298             return *this;
00299         }
00300 
00301         inline Vector4& operator -= ( const Vector4& rkVector )
00302         {
00303             x -= rkVector.x;
00304             y -= rkVector.y;
00305             z -= rkVector.z;
00306             w -= rkVector.w;
00307 
00308             return *this;
00309         }
00310 
00311         inline Vector4& operator *= ( const Real fScalar )
00312         {
00313             x *= fScalar;
00314             y *= fScalar;
00315             z *= fScalar;
00316             w *= fScalar;
00317             return *this;
00318         }
00319 
00320         inline Vector4& operator += ( const Real fScalar )
00321         {
00322             x += fScalar;
00323             y += fScalar;
00324             z += fScalar;
00325             w += fScalar;
00326             return *this;
00327         }
00328 
00329         inline Vector4& operator -= ( const Real fScalar )
00330         {
00331             x -= fScalar;
00332             y -= fScalar;
00333             z -= fScalar;
00334             w -= fScalar;
00335             return *this;
00336         }
00337 
00338         inline Vector4& operator *= ( const Vector4& rkVector )
00339         {
00340             x *= rkVector.x;
00341             y *= rkVector.y;
00342             z *= rkVector.z;
00343             w *= rkVector.w;
00344 
00345             return *this;
00346         }
00347 
00348         inline Vector4& operator /= ( const Real fScalar )
00349         {
00350             assert( fScalar != 0.0 );
00351 
00352             Real fInv = 1.0 / fScalar;
00353 
00354             x *= fInv;
00355             y *= fInv;
00356             z *= fInv;
00357             w *= fInv;
00358 
00359             return *this;
00360         }
00361 
00362         inline Vector4& operator /= ( const Vector4& rkVector )
00363         {
00364             x /= rkVector.x;
00365             y /= rkVector.y;
00366             z /= rkVector.z;
00367             w /= rkVector.w;
00368 
00369             return *this;
00370         }
00371 
00379         inline Real dotProduct(const Vector4& vec) const
00380         {
00381             return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
00382         }
00385         inline _OgreExport friend std::ostream& operator <<
00386             ( std::ostream& o, const Vector4& v )
00387         {
00388             o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
00389             return o;
00390         }
00391         // special
00392         static const Vector4 ZERO;
00393     };
00394 
00395 }
00396 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:58 2007