# 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 Real operator [] ( const size_t i ) const
    00090         {
    00091             assert( i < 4 );
    00092
    00093             return *(&x+i);
    00094         }
    00095
    00096         inline Real& operator [] ( const size_t i )
    00097         {
    00098             assert( i < 4 );
    00099
    00100             return *(&x+i);
    00101         }
    00102
    00104         inline Real* ptr()
    00105         {
    00106             return &x;
    00107         }
    00109         inline const Real* ptr() const
    00110         {
    00111             return &x;
    00112         }
    00113
    00118         inline Vector4& operator = ( const Vector4& rkVector )
    00119         {
    00120             x = rkVector.x;
    00121             y = rkVector.y;
    00122             z = rkVector.z;
    00123             w = rkVector.w;
    00124
    00125             return *this;
    00126         }
    00127
    00128         inline Vector4& operator = ( const Real fScalar)
    00129         {
    00130             x = fScalar;
    00131             y = fScalar;
    00132             z = fScalar;
    00133             w = fScalar;
    00134             return *this;
    00135         }
    00136
    00137         inline bool operator == ( const Vector4& rkVector ) const
    00138         {
    00139             return ( x == rkVector.x &&
    00140                 y == rkVector.y &&
    00141                 z == rkVector.z &&
    00142                 w == rkVector.w );
    00143         }
    00144
    00145         inline bool operator != ( const Vector4& rkVector ) const
    00146         {
    00147             return ( x != rkVector.x ||
    00148                 y != rkVector.y ||
    00149                 z != rkVector.z ||
    00150                 w != rkVector.w );
    00151         }
    00152
    00153         inline Vector4& operator = (const Vector3& rhs)
    00154         {
    00155             x = rhs.x;
    00156             y = rhs.y;
    00157             z = rhs.z;
    00158             w = 1.0f;
    00159             return *this;
    00160         }
    00161
    00162         // arithmetic operations
    00163         inline Vector4 operator + ( const Vector4& rkVector ) const
    00164         {
    00165             return Vector4(
    00166                 x + rkVector.x,
    00167                 y + rkVector.y,
    00168                 z + rkVector.z,
    00169                 w + rkVector.w);
    00170         }
    00171
    00172         inline Vector4 operator - ( const Vector4& rkVector ) const
    00173         {
    00174             return Vector4(
    00175                 x - rkVector.x,
    00176                 y - rkVector.y,
    00177                 z - rkVector.z,
    00178                 w - rkVector.w);
    00179         }
    00180
    00181         inline Vector4 operator * ( const Real fScalar ) const
    00182         {
    00183             return Vector4(
    00184                 x * fScalar,
    00185                 y * fScalar,
    00186                 z * fScalar,
    00187                 w * fScalar);
    00188         }
    00189
    00190         inline Vector4 operator * ( const Vector4& rhs) const
    00191         {
    00192             return Vector4(
    00193                 rhs.x * x,
    00194                 rhs.y * y,
    00195                 rhs.z * z,
    00196                 rhs.w * w);
    00197         }
    00198
    00199         inline Vector4 operator / ( const Real fScalar ) const
    00200         {
    00201             assert( fScalar != 0.0 );
    00202
    00203             Real fInv = 1.0 / fScalar;
    00204
    00205             return Vector4(
    00206                 x * fInv,
    00207                 y * fInv,
    00208                 z * fInv,
    00209                 w * fInv);
    00210         }
    00211
    00212         inline Vector4 operator / ( const Vector4& rhs) const
    00213         {
    00214             return Vector4(
    00215                 x / rhs.x,
    00216                 y / rhs.y,
    00217                 z / rhs.z,
    00218                 w / rhs.w);
    00219         }
    00220
    00221         inline const Vector4& operator + () const
    00222         {
    00223             return *this;
    00224         }
    00225
    00226         inline Vector4 operator - () const
    00227         {
    00228             return Vector4(-x, -y, -z, -w);
    00229         }
    00230
    00231         inline friend Vector4 operator * ( const Real fScalar, const Vector4& rkVector )
    00232         {
    00233             return Vector4(
    00234                 fScalar * rkVector.x,
    00235                 fScalar * rkVector.y,
    00236                 fScalar * rkVector.z,
    00237                 fScalar * rkVector.w);
    00238         }
    00239
    00240         inline friend Vector4 operator / ( const Real fScalar, const Vector4& rkVector )
    00241         {
    00242             return Vector4(
    00243                 fScalar / rkVector.x,
    00244                 fScalar / rkVector.y,
    00245                 fScalar / rkVector.z,
    00246                 fScalar / rkVector.w);
    00247         }
    00248
    00249         inline friend Vector4 operator + (const Vector4& lhs, const Real rhs)
    00250         {
    00251             return Vector4(
    00252                 lhs.x + rhs,
    00253                 lhs.y + rhs,
    00254                 lhs.z + rhs,
    00255                 lhs.w + rhs);
    00256         }
    00257
    00258         inline friend Vector4 operator + (const Real lhs, const Vector4& rhs)
    00259         {
    00260             return Vector4(
    00261                 lhs + rhs.x,
    00262                 lhs + rhs.y,
    00263                 lhs + rhs.z,
    00264                 lhs + rhs.w);
    00265         }
    00266
    00267         inline friend Vector4 operator - (const Vector4& lhs, Real rhs)
    00268         {
    00269             return Vector4(
    00270                 lhs.x - rhs,
    00271                 lhs.y - rhs,
    00272                 lhs.z - rhs,
    00273                 lhs.w - rhs);
    00274         }
    00275
    00276         inline friend Vector4 operator - (const Real lhs, const Vector4& rhs)
    00277         {
    00278             return Vector4(
    00279                 lhs - rhs.x,
    00280                 lhs - rhs.y,
    00281                 lhs - rhs.z,
    00282                 lhs - rhs.w);
    00283         }
    00284
    00285         // arithmetic updates
    00286         inline Vector4& operator += ( const Vector4& rkVector )
    00287         {
    00288             x += rkVector.x;
    00289             y += rkVector.y;
    00290             z += rkVector.z;
    00291             w += rkVector.w;
    00292
    00293             return *this;
    00294         }
    00295
    00296         inline Vector4& operator -= ( const Vector4& rkVector )
    00297         {
    00298             x -= rkVector.x;
    00299             y -= rkVector.y;
    00300             z -= rkVector.z;
    00301             w -= rkVector.w;
    00302
    00303             return *this;
    00304         }
    00305
    00306         inline Vector4& operator *= ( const Real fScalar )
    00307         {
    00308             x *= fScalar;
    00309             y *= fScalar;
    00310             z *= fScalar;
    00311             w *= fScalar;
    00312             return *this;
    00313         }
    00314
    00315         inline Vector4& operator += ( const Real fScalar )
    00316         {
    00317             x += fScalar;
    00318             y += fScalar;
    00319             z += fScalar;
    00320             w += fScalar;
    00321             return *this;
    00322         }
    00323
    00324         inline Vector4& operator -= ( const Real fScalar )
    00325         {
    00326             x -= fScalar;
    00327             y -= fScalar;
    00328             z -= fScalar;
    00329             w -= fScalar;
    00330             return *this;
    00331         }
    00332
    00333         inline Vector4& operator *= ( const Vector4& rkVector )
    00334         {
    00335             x *= rkVector.x;
    00336             y *= rkVector.y;
    00337             z *= rkVector.z;
    00338             w *= rkVector.w;
    00339
    00340             return *this;
    00341         }
    00342
    00343         inline Vector4& operator /= ( const Real fScalar )
    00344         {
    00345             assert( fScalar != 0.0 );
    00346
    00347             Real fInv = 1.0 / fScalar;
    00348
    00349             x *= fInv;
    00350             y *= fInv;
    00351             z *= fInv;
    00352             w *= fInv;
    00353
    00354             return *this;
    00355         }
    00356
    00357         inline Vector4& operator /= ( const Vector4& rkVector )
    00358         {
    00359             x /= rkVector.x;
    00360             y /= rkVector.y;
    00361             z /= rkVector.z;
    00362             w /= rkVector.w;
    00363
    00364             return *this;
    00365         }
    00366
    00374         inline Real dotProduct(const Vector4& vec) const
    00375         {
    00376             return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
    00377         }
    00380         inline _OgreExport friend std::ostream& operator <<
    00381             ( std::ostream& o, const Vector4& v )
    00382         {
    00383             o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
    00384             return o;
    00385         }
    00386         // special
    00387         static const Vector4 ZERO;
    00388     };
    00389
    00390 }
    00391 #endif

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Dec 27 17:31:08 2009