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-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Vector4_H__ 00029 #define __Vector4_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreVector3.h" 00033 00034 namespace Ogre 00035 { 00036 00045 class _OgreExport Vector4 00046 { 00047 public: 00048 Real x, y, z, w; 00049 00050 public: 00051 inline Vector4() 00052 { 00053 } 00054 00055 inline Vector4( const Real fX, const Real fY, const Real fZ, const Real fW ) 00056 : x( fX ), y( fY ), z( fZ ), w( fW) 00057 { 00058 } 00059 00060 inline explicit Vector4( const Real afCoordinate[4] ) 00061 : x( afCoordinate[0] ), 00062 y( afCoordinate[1] ), 00063 z( afCoordinate[2] ), 00064 w( afCoordinate[3] ) 00065 { 00066 } 00067 00068 inline explicit Vector4( const int afCoordinate[4] ) 00069 { 00070 x = (Real)afCoordinate[0]; 00071 y = (Real)afCoordinate[1]; 00072 z = (Real)afCoordinate[2]; 00073 w = (Real)afCoordinate[3]; 00074 } 00075 00076 inline explicit Vector4( Real* const r ) 00077 : x( r[0] ), y( r[1] ), z( r[2] ), w( r[3] ) 00078 { 00079 } 00080 00081 inline explicit Vector4( const Real scaler ) 00082 : x( scaler ) 00083 , y( scaler ) 00084 , z( scaler ) 00085 , w( scaler ) 00086 { 00087 } 00088 00089 inline explicit Vector4(const Vector3& rhs) 00090 : x(rhs.x), y(rhs.y), z(rhs.z), w(1.0f) 00091 { 00092 } 00093 00096 inline void swap(Vector4& other) 00097 { 00098 std::swap(x, other.x); 00099 std::swap(y, other.y); 00100 std::swap(z, other.z); 00101 std::swap(w, other.w); 00102 } 00103 00104 inline Real operator [] ( const size_t i ) const 00105 { 00106 assert( i < 4 ); 00107 00108 return *(&x+i); 00109 } 00110 00111 inline Real& operator [] ( const size_t i ) 00112 { 00113 assert( i < 4 ); 00114 00115 return *(&x+i); 00116 } 00117 00119 inline Real* ptr() 00120 { 00121 return &x; 00122 } 00124 inline const Real* ptr() const 00125 { 00126 return &x; 00127 } 00128 00133 inline Vector4& operator = ( const Vector4& rkVector ) 00134 { 00135 x = rkVector.x; 00136 y = rkVector.y; 00137 z = rkVector.z; 00138 w = rkVector.w; 00139 00140 return *this; 00141 } 00142 00143 inline Vector4& operator = ( const Real fScalar) 00144 { 00145 x = fScalar; 00146 y = fScalar; 00147 z = fScalar; 00148 w = fScalar; 00149 return *this; 00150 } 00151 00152 inline bool operator == ( const Vector4& rkVector ) const 00153 { 00154 return ( x == rkVector.x && 00155 y == rkVector.y && 00156 z == rkVector.z && 00157 w == rkVector.w ); 00158 } 00159 00160 inline bool operator != ( const Vector4& rkVector ) const 00161 { 00162 return ( x != rkVector.x || 00163 y != rkVector.y || 00164 z != rkVector.z || 00165 w != rkVector.w ); 00166 } 00167 00168 inline Vector4& operator = (const Vector3& rhs) 00169 { 00170 x = rhs.x; 00171 y = rhs.y; 00172 z = rhs.z; 00173 w = 1.0f; 00174 return *this; 00175 } 00176 00177 // arithmetic operations 00178 inline Vector4 operator + ( const Vector4& rkVector ) const 00179 { 00180 return Vector4( 00181 x + rkVector.x, 00182 y + rkVector.y, 00183 z + rkVector.z, 00184 w + rkVector.w); 00185 } 00186 00187 inline Vector4 operator - ( const Vector4& rkVector ) const 00188 { 00189 return Vector4( 00190 x - rkVector.x, 00191 y - rkVector.y, 00192 z - rkVector.z, 00193 w - rkVector.w); 00194 } 00195 00196 inline Vector4 operator * ( const Real fScalar ) const 00197 { 00198 return Vector4( 00199 x * fScalar, 00200 y * fScalar, 00201 z * fScalar, 00202 w * fScalar); 00203 } 00204 00205 inline Vector4 operator * ( const Vector4& rhs) const 00206 { 00207 return Vector4( 00208 rhs.x * x, 00209 rhs.y * y, 00210 rhs.z * z, 00211 rhs.w * w); 00212 } 00213 00214 inline Vector4 operator / ( const Real fScalar ) const 00215 { 00216 assert( fScalar != 0.0 ); 00217 00218 Real fInv = 1.0f / fScalar; 00219 00220 return Vector4( 00221 x * fInv, 00222 y * fInv, 00223 z * fInv, 00224 w * fInv); 00225 } 00226 00227 inline Vector4 operator / ( const Vector4& rhs) const 00228 { 00229 return Vector4( 00230 x / rhs.x, 00231 y / rhs.y, 00232 z / rhs.z, 00233 w / rhs.w); 00234 } 00235 00236 inline const Vector4& operator + () const 00237 { 00238 return *this; 00239 } 00240 00241 inline Vector4 operator - () const 00242 { 00243 return Vector4(-x, -y, -z, -w); 00244 } 00245 00246 inline friend Vector4 operator * ( const Real fScalar, const Vector4& rkVector ) 00247 { 00248 return Vector4( 00249 fScalar * rkVector.x, 00250 fScalar * rkVector.y, 00251 fScalar * rkVector.z, 00252 fScalar * rkVector.w); 00253 } 00254 00255 inline friend Vector4 operator / ( const Real fScalar, const Vector4& rkVector ) 00256 { 00257 return Vector4( 00258 fScalar / rkVector.x, 00259 fScalar / rkVector.y, 00260 fScalar / rkVector.z, 00261 fScalar / rkVector.w); 00262 } 00263 00264 inline friend Vector4 operator + (const Vector4& lhs, const Real rhs) 00265 { 00266 return Vector4( 00267 lhs.x + rhs, 00268 lhs.y + rhs, 00269 lhs.z + rhs, 00270 lhs.w + rhs); 00271 } 00272 00273 inline friend Vector4 operator + (const Real lhs, const Vector4& rhs) 00274 { 00275 return Vector4( 00276 lhs + rhs.x, 00277 lhs + rhs.y, 00278 lhs + rhs.z, 00279 lhs + rhs.w); 00280 } 00281 00282 inline friend Vector4 operator - (const Vector4& lhs, Real rhs) 00283 { 00284 return Vector4( 00285 lhs.x - rhs, 00286 lhs.y - rhs, 00287 lhs.z - rhs, 00288 lhs.w - rhs); 00289 } 00290 00291 inline friend Vector4 operator - (const Real lhs, const Vector4& rhs) 00292 { 00293 return Vector4( 00294 lhs - rhs.x, 00295 lhs - rhs.y, 00296 lhs - rhs.z, 00297 lhs - rhs.w); 00298 } 00299 00300 // arithmetic updates 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 Vector4& rkVector ) 00312 { 00313 x -= rkVector.x; 00314 y -= rkVector.y; 00315 z -= rkVector.z; 00316 w -= rkVector.w; 00317 00318 return *this; 00319 } 00320 00321 inline Vector4& operator *= ( const Real fScalar ) 00322 { 00323 x *= fScalar; 00324 y *= fScalar; 00325 z *= fScalar; 00326 w *= fScalar; 00327 return *this; 00328 } 00329 00330 inline Vector4& operator += ( const Real fScalar ) 00331 { 00332 x += fScalar; 00333 y += fScalar; 00334 z += fScalar; 00335 w += fScalar; 00336 return *this; 00337 } 00338 00339 inline Vector4& operator -= ( const Real fScalar ) 00340 { 00341 x -= fScalar; 00342 y -= fScalar; 00343 z -= fScalar; 00344 w -= fScalar; 00345 return *this; 00346 } 00347 00348 inline Vector4& operator *= ( const Vector4& rkVector ) 00349 { 00350 x *= rkVector.x; 00351 y *= rkVector.y; 00352 z *= rkVector.z; 00353 w *= rkVector.w; 00354 00355 return *this; 00356 } 00357 00358 inline Vector4& operator /= ( const Real fScalar ) 00359 { 00360 assert( fScalar != 0.0 ); 00361 00362 Real fInv = 1.0f / fScalar; 00363 00364 x *= fInv; 00365 y *= fInv; 00366 z *= fInv; 00367 w *= fInv; 00368 00369 return *this; 00370 } 00371 00372 inline Vector4& operator /= ( const Vector4& rkVector ) 00373 { 00374 x /= rkVector.x; 00375 y /= rkVector.y; 00376 z /= rkVector.z; 00377 w /= rkVector.w; 00378 00379 return *this; 00380 } 00381 00389 inline Real dotProduct(const Vector4& vec) const 00390 { 00391 return x * vec.x + y * vec.y + z * vec.z + w * vec.w; 00392 } 00394 inline bool isNaN() const 00395 { 00396 return Math::isNaN(x) || Math::isNaN(y) || Math::isNaN(z) || Math::isNaN(w); 00397 } 00400 inline _OgreExport friend std::ostream& operator << 00401 ( std::ostream& o, const Vector4& v ) 00402 { 00403 o << "Vector4(" << v.x << ", " << v.y << ", " << v.z << ", " << v.w << ")"; 00404 return o; 00405 } 00406 // special 00407 static const Vector4 ZERO; 00408 }; 00412 } 00413 #endif 00414
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:28 2012