PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Vector3i.h * 00003 * 00004 * Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLMATH_VECTOR3I_H__ 00024 #define __PLMATH_VECTOR3I_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/String/String.h> 00032 #include "PLMath/PLMath.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLMath { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class Vector2i; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * 3D integer vector 00053 */ 00054 class Vector3i { 00055 00056 00057 //[-------------------------------------------------------] 00058 //[ Public static data ] 00059 //[-------------------------------------------------------] 00060 public: 00061 static PLMATH_API const Vector3i Zero; /**< 0, 0, 0 */ 00062 static PLMATH_API const Vector3i One; /**< 1, 1, 1 */ 00063 static PLMATH_API const Vector3i NegativeOne; /**< -1, -1, -1 */ 00064 static PLMATH_API const Vector3i UnitX; /**< 1, 0, 0 */ 00065 static PLMATH_API const Vector3i UnitY; /**< 0, 1, 0 */ 00066 static PLMATH_API const Vector3i UnitZ; /**< 0, 0, 1 */ 00067 static PLMATH_API const Vector3i NegativeUnitX; /**< -1, 0, 0 */ 00068 static PLMATH_API const Vector3i NegativeUnitY; /**< 0, -1, 0 */ 00069 static PLMATH_API const Vector3i NegativeUnitZ; /**< 0, 0, -1 */ 00070 00071 00072 //[-------------------------------------------------------] 00073 //[ Public data ] 00074 //[-------------------------------------------------------] 00075 public: 00076 /** 00077 * @brief 00078 * Some direct vector element accesses 00079 */ 00080 union { 00081 /** 00082 * @brief 00083 * Vector element array access 00084 */ 00085 int nV[3]; 00086 00087 /** 00088 * @brief 00089 * Known vector element names when dealing with positions or directions 00090 */ 00091 struct { 00092 int x, y, z; 00093 }; 00094 00095 /** 00096 * @brief 00097 * Known vector element names when dealing with sizes 00098 */ 00099 struct { 00100 int width, height, depth; 00101 }; 00102 }; 00103 00104 00105 //[-------------------------------------------------------] 00106 //[ Public functions ] 00107 //[-------------------------------------------------------] 00108 public: 00109 /** 00110 * @brief 00111 * Default constructor setting all components to 0 00112 */ 00113 inline Vector3i(); 00114 00115 /** 00116 * @brief 00117 * Constructor 00118 * 00119 * @param[in] nX 00120 * X component 00121 * @param[in] nY 00122 * Y component 00123 * @param[in] nZ 00124 * Z component 00125 */ 00126 inline Vector3i(int nX, int nY, int nZ); 00127 00128 /** 00129 * @brief 00130 * Constructor 00131 * 00132 * @param[in] vVector 00133 * 2D vector to copy the x and y values from 00134 * @param[in] nZ 00135 * Z component 00136 */ 00137 PLMATH_API Vector3i(const Vector2i &vVector, int nZ); 00138 00139 /** 00140 * @brief 00141 * Destructor 00142 */ 00143 inline ~Vector3i(); 00144 00145 //[-------------------------------------------------------] 00146 //[ Get and set ] 00147 //[-------------------------------------------------------] 00148 inline operator int *(); 00149 inline operator const int *() const; 00150 inline int &operator [](int nIndex); 00151 inline const int &operator [](int nIndex) const; 00152 00153 /** 00154 * @brief 00155 * Set vector 00156 * 00157 * @param[in] nX 00158 * X component 00159 * @param[in] nY 00160 * Y component 00161 * @param[in] nZ 00162 * Z component 00163 */ 00164 inline void Set(int nX, int nY, int nZ); 00165 00166 /** 00167 * @brief 00168 * Set X component 00169 * 00170 * @param[in] nX 00171 * X component 00172 */ 00173 inline void SetX(int nX); 00174 00175 /** 00176 * @brief 00177 * Set Y component 00178 * 00179 * @param[in] nY 00180 * Y component 00181 */ 00182 inline void SetY(int nY); 00183 00184 /** 00185 * @brief 00186 * Set X, Y and Z component 00187 * 00188 * @param[in] vXY 00189 * Vector2 instance to take the X and Y components from 00190 * @param[in] nZ 00191 * Z component value 00192 */ 00193 PLMATH_API void SetXYZ(const Vector2i &vXY, int nZ = 0); 00194 00195 /** 00196 * @brief 00197 * Set Z component 00198 * 00199 * @param[in] nZ 00200 * Z component 00201 */ 00202 inline void SetZ(int nZ); 00203 00204 /** 00205 * @brief 00206 * Assignment operator 00207 * 00208 * @param[in] vV 00209 * Source vector to copy 00210 * 00211 * @return 00212 * This vector 00213 */ 00214 inline Vector3i &operator =(const Vector3i &vV); 00215 00216 /** 00217 * @brief 00218 * Compare operator 00219 * 00220 * @param[in] vV 00221 * Vector to compare with 00222 * 00223 * @return 00224 * 'true' if equal, else 'false' 00225 */ 00226 inline bool operator ==(const Vector3i &vV) const; 00227 00228 /** 00229 * @brief 00230 * Compare operator 00231 * 00232 * @param[in] vV 00233 * Vector to compare with 00234 * 00235 * @return 00236 * 'true' if not equal, else 'false' 00237 */ 00238 inline bool operator !=(const Vector3i &vV) const; 00239 00240 /** 00241 * @brief 00242 * Compares two vectors lexicographically 00243 * 00244 * @param[in] vV 00245 * Vector to compare with 00246 * 00247 * @return 00248 * 'true' if ALL components of this vector are less, else 'false' 00249 * 00250 * @note 00251 * - A lexicographical order for 3-dimensional vectors is used (see http://en.wikipedia.org/wiki/Ordered_vector_space) 00252 */ 00253 inline bool operator <(const Vector3i &vV) const; 00254 00255 /** 00256 * @brief 00257 * Compares two vectors lexicographically 00258 * 00259 * @param[in] vV 00260 * Vector to compare with 00261 * 00262 * @return 00263 * 'true' if ALL components of this vector are greater, else 'false' 00264 * 00265 * @see 00266 * - "operator <" 00267 */ 00268 inline bool operator >(const Vector3i &vV) const; 00269 00270 /** 00271 * @brief 00272 * Compares two vectors lexicographically 00273 * 00274 * @param[in] vV 00275 * Vector to compare with 00276 * 00277 * @return 00278 * 'true' if ALL components of this vector are less or equal, else 'false' 00279 * 00280 * @see 00281 * - "operator <" 00282 */ 00283 inline bool operator <=(const Vector3i &vV) const; 00284 00285 /** 00286 * @brief 00287 * Compares two vectors lexicographically 00288 * 00289 * @param[in] vV 00290 * Vector to compare with 00291 * 00292 * @return 00293 * 'true' if ALL components of this vector are greater or equal, else 'false' 00294 * 00295 * @see 00296 * - "operator <" 00297 */ 00298 inline bool operator >=(const Vector3i &vV) const; 00299 00300 /** 00301 * @brief 00302 * Addition operator 00303 * 00304 * @param[in] vV 00305 * Vector to add 00306 * 00307 * @return 00308 * The resulting vector 00309 */ 00310 inline Vector3i operator +(const Vector3i &vV) const; 00311 00312 /** 00313 * @brief 00314 * Addition operator 00315 * 00316 * @param[in] vV 00317 * Vector to add 00318 * 00319 * @return 00320 * This vector 00321 */ 00322 inline Vector3i &operator +=(const Vector3i &vV); 00323 00324 /** 00325 * @brief 00326 * Subtraction operator 00327 * 00328 * @param[in] vV 00329 * Vector to subtract 00330 * 00331 * @return 00332 * The resulting vector 00333 */ 00334 inline Vector3i operator -(const Vector3i &vV) const; 00335 00336 /** 00337 * @brief 00338 * Subtraction operator 00339 * 00340 * @param[in] vV 00341 * Vector to subtract 00342 * 00343 * @return 00344 * This vector 00345 */ 00346 inline Vector3i &operator -=(const Vector3i &vV); 00347 00348 /** 00349 * @brief 00350 * Multiplication operator 00351 * 00352 * @param[in] fFactor 00353 * Floating point factor 00354 * 00355 * @return 00356 * The resulting vector 00357 */ 00358 inline Vector3i operator *(float fFactor) const; 00359 00360 /** 00361 * @brief 00362 * Multiplication operator 00363 * 00364 * @param[in] fFactor 00365 * Floating point factor 00366 * 00367 * @return 00368 * This vector 00369 */ 00370 inline Vector3i &operator *=(float fFactor); 00371 00372 /** 00373 * @brief 00374 * Division operator 00375 * 00376 * @param[in] fFactor 00377 * Floating point divisor 00378 * 00379 * @return 00380 * The resulting vector 00381 */ 00382 inline Vector3i operator /(float fFactor) const; 00383 00384 /** 00385 * @brief 00386 * Division operator 00387 * 00388 * @param[in] fFactor 00389 * Floating point divisor 00390 * 00391 * @return 00392 * This vector 00393 */ 00394 inline Vector3i &operator /=(float fFactor); 00395 00396 /** 00397 * @brief 00398 * To string 00399 * 00400 * @return 00401 * String with the data 00402 */ 00403 PLMATH_API PLCore::String ToString() const; 00404 00405 /** 00406 * @brief 00407 * From string 00408 * 00409 * @param[in] sString 00410 * String with the data 00411 */ 00412 PLMATH_API bool FromString(const PLCore::String &sString); 00413 00414 00415 }; 00416 00417 00418 //[-------------------------------------------------------] 00419 //[ Namespace ] 00420 //[-------------------------------------------------------] 00421 } // PLMath 00422 00423 00424 //[-------------------------------------------------------] 00425 //[ Implementation ] 00426 //[-------------------------------------------------------] 00427 #include "PLMath/Vector3i.inl" 00428 #include "PLMath/TypeVector3i.inl" 00429 00430 00431 #endif // __PLMATH_VECTOR3I_H__
|