00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://ogre.sourceforge.net/ 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 Real x, y, z, w; 00041 00042 public: 00043 inline Vector4() 00044 { 00045 } 00046 00047 inline Vector4( Real fX, Real fY, Real fZ, Real fW ) 00048 : x( fX ), y( fY ), z( fZ ), w( fW) 00049 { 00050 } 00051 00052 inline Vector4( Real afCoordinate[4] ) 00053 : x( afCoordinate[0] ), 00054 y( afCoordinate[1] ), 00055 z( afCoordinate[2] ), 00056 w (afCoordinate[3] ) 00057 { 00058 } 00059 00060 inline Vector4( int afCoordinate[4] ) 00061 { 00062 x = (Real)afCoordinate[0]; 00063 y = (Real)afCoordinate[1]; 00064 z = (Real)afCoordinate[2]; 00065 w = (Real)afCoordinate[3]; 00066 } 00067 00068 inline Vector4( const Real* const r ) 00069 : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] ) 00070 { 00071 } 00072 00073 inline Vector4( const Vector4& rkVector ) 00074 : x( rkVector.x ), y( rkVector.y ), z( rkVector.z ), w (rkVector.w) 00075 { 00076 } 00077 00078 inline Real operator [] ( unsigned i ) const 00079 { 00080 assert( i < 4 ); 00081 00082 return *(&x+i); 00083 } 00084 00085 inline Real& operator [] ( unsigned i ) 00086 { 00087 assert( i < 4 ); 00088 00089 return *(&x+i); 00090 } 00091 00096 inline Vector4& operator = ( const Vector4& rkVector ) 00097 { 00098 x = rkVector.x; 00099 y = rkVector.y; 00100 z = rkVector.z; 00101 w = rkVector.w; 00102 00103 return *this; 00104 } 00105 00106 inline bool operator == ( const Vector4& rkVector ) const 00107 { 00108 return ( x == rkVector.x && 00109 y == rkVector.y && 00110 z == rkVector.z && 00111 w == rkVector.w ); 00112 } 00113 00114 inline bool operator != ( const Vector4& rkVector ) const 00115 { 00116 return ( x != rkVector.x || 00117 y != rkVector.y || 00118 z != rkVector.z || 00119 w != rkVector.w ); 00120 } 00121 00122 inline Vector4& operator = (const Vector3& rhs) 00123 { 00124 x = rhs.x; 00125 y = rhs.y; 00126 z = rhs.z; 00127 w = 1.0f; 00128 return *this; 00129 } 00130 00131 inline Vector4 operator * (const Matrix4& mat) 00132 { 00133 return Vector4( 00134 x*mat[0][0] + y*mat[1][0] + z*mat[2][0] + w*mat[3][0], 00135 x*mat[0][1] + y*mat[1][1] + z*mat[2][1] + w*mat[3][1], 00136 x*mat[0][2] + y*mat[1][2] + z*mat[2][2] + w*mat[3][2], 00137 x*mat[0][3] + y*mat[1][3] + z*mat[2][3] + w*mat[3][3] 00138 ); 00139 } 00140 00141 00144 inline _OgreExport friend std::ostream& operator << 00145 ( std::ostream& o, const Vector4& v ) 00146 { 00147 o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")"; 00148 return o; 00149 } 00150 }; 00151 00152 } 00153 #endif
Copyright © 2002 by The OGRE Team