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 #include "OgreMatrix4.h"
00031 
00032 namespace Ogre
00033 {
00034 
00037     class _OgreExport Vector4
00038     {
00039     public:
00040         union {
00041             struct {
00042                 Real x, y, z, w;        
00043             };
00044             Real val[4];
00045         };
00046 
00047     public:
00048         inline Vector4()
00049         {
00050         }
00051 
00052         inline Vector4( Real fX, Real fY, Real fZ, Real fW ) 
00053             : x( fX ), y( fY ), z( fZ ), w( fW)
00054         {
00055         }
00056 
00057         inline Vector4( Real afCoordinate[4] )
00058             : x( afCoordinate[0] ),
00059               y( afCoordinate[1] ),
00060               z( afCoordinate[2] ), 
00061               w (afCoordinate[3] )
00062         {
00063         }
00064 
00065         inline Vector4( int afCoordinate[4] )
00066         {
00067             x = (Real)afCoordinate[0];
00068             y = (Real)afCoordinate[1];
00069             z = (Real)afCoordinate[2];
00070             w = (Real)afCoordinate[3];
00071         }
00072 
00073         inline Vector4( const Real* const r )
00074             : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] )
00075         {
00076         }
00077 
00078         inline Vector4( const Vector4& rkVector )
00079             : x( rkVector.x ), y( rkVector.y ), z( rkVector.z ), w (rkVector.w)
00080         {
00081         }
00082 
00083         inline Real operator [] ( unsigned i ) const
00084         {
00085             assert( i < 4 );
00086 
00087             return *(&x+i);
00088         }
00089 
00090         inline Real& operator [] ( unsigned i )
00091         {
00092             assert( i < 4 );
00093 
00094             return *(&x+i);
00095         }
00096 
00101         inline Vector4& operator = ( const Vector4& rkVector )
00102         {
00103             x = rkVector.x;
00104             y = rkVector.y;
00105             z = rkVector.z;            
00106             w = rkVector.w;            
00107 
00108             return *this;
00109         }
00110 
00111         inline bool operator == ( const Vector4& rkVector ) const
00112         {
00113             return ( x == rkVector.x && 
00114                 y == rkVector.y && 
00115                 z == rkVector.z &&
00116                 w == rkVector.w );
00117         }
00118 
00119         inline bool operator != ( const Vector4& rkVector ) const
00120         {
00121             return ( x != rkVector.x || 
00122                 y != rkVector.y || 
00123                 z != rkVector.z ||
00124                 w != rkVector.w );
00125         }
00126 
00127         inline Vector4& operator = (const Vector3& rhs)
00128         {
00129             x = rhs.x;
00130             y = rhs.y;
00131             z = rhs.z;
00132             w = 1.0f;
00133             return *this;
00134         }
00135 
00136         inline Vector4 operator * (const Matrix4& mat) const
00137         {
00138             return Vector4(
00139                 x*mat[0][0] + y*mat[1][0] + z*mat[2][0] + w*mat[3][0],
00140                 x*mat[0][1] + y*mat[1][1] + z*mat[2][1] + w*mat[3][1],
00141                 x*mat[0][2] + y*mat[1][2] + z*mat[2][2] + w*mat[3][2],
00142                 x*mat[0][3] + y*mat[1][3] + z*mat[2][3] + w*mat[3][3]
00143                 );
00144         }
00145 
00146 
00154         inline Real dotProduct(const Vector4& vec) const
00155         {
00156             return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
00157         }
00160         inline _OgreExport friend std::ostream& operator <<
00161             ( std::ostream& o, const Vector4& v )
00162         {
00163             o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")";
00164             return o;
00165         }
00166     };
00167 
00168 }
00169 #endif

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:31 2004