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 00136 00144 inline Real dotProduct(const Vector4& vec) const 00145 { 00146 return x * vec.x + y * vec.y + z * vec.z + w * vec.w; 00147 } 00150 inline _OgreExport friend std::ostream& operator << 00151 ( std::ostream& o, const Vector4& v ) 00152 { 00153 o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")"; 00154 return o; 00155 } 00156 }; 00157 00158 } 00159 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:54 2004