Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 13/2/2011 00003 author: Martin Preisler (reworked from code by Paul D Turner) 00004 00005 purpose: Defines interfaces for Vector classes 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files (the 00012 * "Software"), to deal in the Software without restriction, including 00013 * without limitation the rights to use, copy, modify, merge, publish, 00014 * distribute, sublicense, and/or sell copies of the Software, and to 00015 * permit persons to whom the Software is furnished to do so, subject to 00016 * the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00025 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00026 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00027 * OTHER DEALINGS IN THE SOFTWARE. 00028 ***************************************************************************/ 00029 #ifndef _CEGUIVector_h_ 00030 #define _CEGUIVector_h_ 00031 00032 #include "CEGUI/UDim.h" 00033 #include <typeinfo> 00034 #include <ostream> 00035 00036 // Start of CEGUI namespace section 00037 namespace CEGUI 00038 { 00039 00052 template<typename T> 00053 class Vector2: 00054 public AllocatedObject<Vector2<T> > 00055 { 00056 public: 00057 typedef T value_type; 00058 00059 inline Vector2() 00060 {} 00061 00062 inline Vector2(const T x, const T y): 00063 d_x(x), 00064 d_y(y) 00065 {} 00066 00067 inline Vector2(const Vector2& v): 00068 d_x(v.d_x), 00069 d_y(v.d_y) 00070 {} 00071 00072 inline Vector2& operator*=(const Vector2& vec) 00073 { 00074 d_x *= vec.d_x; 00075 d_y *= vec.d_y; 00076 00077 return *this; 00078 } 00079 00080 inline Vector2& operator/=(const Vector2& vec) 00081 { 00082 d_x /= vec.d_x; 00083 d_y /= vec.d_y; 00084 00085 return *this; 00086 } 00087 00088 inline Vector2& operator+=(const Vector2& vec) 00089 { 00090 d_x += vec.d_x; 00091 d_y += vec.d_y; 00092 00093 return *this; 00094 } 00095 00096 inline Vector2& operator-=(const Vector2& vec) 00097 { 00098 d_x -= vec.d_x; 00099 d_y -= vec.d_y; 00100 00101 return *this; 00102 } 00103 00104 inline Vector2 operator+(const Vector2& vec) const 00105 { 00106 return Vector2(d_x + vec.d_x, d_y + vec.d_y); 00107 } 00108 00109 inline Vector2 operator-(const Vector2& vec) const 00110 { 00111 return Vector2(d_x - vec.d_x, d_y - vec.d_y); 00112 } 00113 00114 inline Vector2 operator*(const Vector2& vec) const 00115 { 00116 return Vector2(d_x * vec.d_x, d_y * vec.d_y); 00117 } 00118 00119 inline Vector2 operator/(const Vector2& vec) const 00120 { 00121 return Vector2(d_x / vec.d_x, d_y / vec.d_y); 00122 } 00123 00124 inline Vector2 operator*(const T c) const 00125 { 00126 return Vector2(d_x * c, d_y * c); 00127 } 00128 00129 inline Vector2& operator*=(const T c) 00130 { 00131 d_x *= c; 00132 d_y *= c; 00133 00134 return *this; 00135 } 00136 00137 inline Vector2 operator/(const T c) const 00138 { 00139 return Vector2(d_x / c, d_y / c); 00140 } 00141 00142 inline bool operator==(const Vector2& vec) const 00143 { 00144 return ((d_x == vec.d_x) && (d_y == vec.d_y)); 00145 } 00146 00147 inline bool operator!=(const Vector2& vec) const 00148 { 00149 return !(operator==(vec)); 00150 } 00151 00155 inline friend std::ostream& operator << (std::ostream& s, const Vector2& v) 00156 { 00157 s << "CEGUI::Vector2<" << typeid(T).name() << ">(" << v.d_x << ", " << v.d_y << ")"; 00158 return s; 00159 } 00160 00162 inline static Vector2 zero() 00163 { 00164 return Vector2(TypeSensitiveZero<T>(), TypeSensitiveZero<T>()); 00165 } 00166 00168 inline static Vector2 one() 00169 { 00170 return Vector2(TypeSensitiveOne<T>(), TypeSensitiveOne<T>()); 00171 } 00172 00174 inline static Vector2 one_x() 00175 { 00176 return Vector2(TypeSensitiveOne<T>(), TypeSensitiveZero<T>()); 00177 } 00178 00180 inline static Vector2 one_y() 00181 { 00182 return Vector2(TypeSensitiveZero<T>(), TypeSensitiveOne<T>()); 00183 } 00184 00185 T d_x; 00186 T d_y; 00187 }; 00188 00189 // the main reason for this is to keep C++ API in sync with other languages 00190 typedef Vector2<float> Vector2f; 00191 00192 // we need to allow UVector2 to be multiplied by floats, this is the most elegant way to do that 00193 inline Vector2<UDim> operator * (const Vector2<UDim>& v, const float c) 00194 { 00195 return Vector2<UDim>(v.d_x * c, v.d_y * c); 00196 } 00197 00198 typedef Vector2<UDim> UVector2; 00199 00212 template<typename T> 00213 class Vector3: 00214 public AllocatedObject<Vector3<T> > 00215 { 00216 public: 00217 typedef T value_type; 00218 00219 inline Vector3() 00220 {} 00221 00222 inline Vector3(const T x, const T y, const T z): 00223 d_x(x), 00224 d_y(y), 00225 d_z(z) 00226 {} 00227 00228 inline explicit Vector3(const Vector2<T>& v, const T z): 00229 d_x(v.d_x), 00230 d_y(v.d_y), 00231 d_z(z) 00232 {} 00233 00234 inline Vector3(const Vector3& v): 00235 d_x(v.d_x), 00236 d_y(v.d_y), 00237 d_z(v.d_z) 00238 {} 00239 00240 inline bool operator==(const Vector3& vec) const 00241 { 00242 return ((d_x == vec.d_x) && (d_y == vec.d_y) && (d_z == vec.d_z)); 00243 } 00244 00245 inline bool operator!=(const Vector3& vec) const 00246 { 00247 return !(operator==(vec)); 00248 } 00249 00250 inline Vector3 operator*(const T c) const 00251 { 00252 return Vector3(d_x * c, d_y * c, d_z * c); 00253 } 00254 00255 inline Vector3 operator+(const Vector3& v) const 00256 { 00257 return Vector3(d_x + v.d_x, d_y + v.d_y, d_z + v.d_z); 00258 } 00259 00260 inline Vector3 operator-(const Vector3& v) const 00261 { 00262 return Vector3(d_x - v.d_x, d_y - v.d_y, d_z - v.d_z); 00263 } 00264 00268 inline friend std::ostream& operator << (std::ostream& s, const Vector3& v) 00269 { 00270 s << "CEGUI::Vector3<" << typeid(T).name() << ">(" << v.d_x << ", " << v.d_y << ", " << v.d_z << ")"; 00271 return s; 00272 } 00273 00275 inline static Vector3 zero() 00276 { 00277 return Vector3(TypeSensitiveZero<T>(), TypeSensitiveZero<T>(), TypeSensitiveZero<T>()); 00278 } 00279 00281 inline static Vector3 one() 00282 { 00283 return Vector3(TypeSensitiveOne<T>(), TypeSensitiveOne<T>(), TypeSensitiveOne<T>()); 00284 } 00285 00287 inline static Vector3 one_x() 00288 { 00289 return Vector3(TypeSensitiveOne<T>(), TypeSensitiveZero<T>(), TypeSensitiveZero<T>()); 00290 } 00291 00293 inline static Vector3 one_y() 00294 { 00295 return Vector3(TypeSensitiveZero<T>(), TypeSensitiveOne<T>(), TypeSensitiveZero<T>()); 00296 } 00297 00299 inline static Vector3 one_z() 00300 { 00301 return Vector3(TypeSensitiveZero<T>(), TypeSensitiveZero<T>(), TypeSensitiveOne<T>()); 00302 } 00303 00304 T d_x; 00305 T d_y; 00306 T d_z; 00307 }; 00308 00309 // the main reason for this is to keep C++ API in sync with other languages 00310 typedef Vector3<float> Vector3f; 00311 00312 } // End of CEGUI namespace section 00313 00314 #endif // end of guard _CEGUIVector_h_