Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
Vector.h
1/***********************************************************************
2 created: 13/2/2011
3 author: Martin Preisler (reworked from code by Paul D Turner)
4
5 purpose: Defines interfaces for Vector classes
6*************************************************************************/
7/***************************************************************************
8 * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the
12 * "Software"), to deal in the Software without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 ***************************************************************************/
29#ifndef _CEGUIVector_h_
30#define _CEGUIVector_h_
31
32#include "CEGUI/UDim.h"
33#include <typeinfo>
34#include <ostream>
35
36// Start of CEGUI namespace section
37namespace CEGUI
38{
39
52template<typename T>
53class Vector2:
54 public AllocatedObject<Vector2<T> >
55{
56public:
57 typedef T value_type;
58
59 inline Vector2()
60 :d_x(T())
61 ,d_y(T())
62 {}
63
64 inline Vector2(const T x, const T y):
65 d_x(x),
66 d_y(y)
67 {}
68
69 inline Vector2(const Vector2& v):
70 d_x(v.d_x),
71 d_y(v.d_y)
72 {}
73
74 inline Vector2& operator*=(const Vector2& vec)
75 {
76 d_x *= vec.d_x;
77 d_y *= vec.d_y;
78
79 return *this;
80 }
81
82 inline Vector2& operator/=(const Vector2& vec)
83 {
84 d_x /= vec.d_x;
85 d_y /= vec.d_y;
86
87 return *this;
88 }
89
90 inline Vector2& operator+=(const Vector2& vec)
91 {
92 d_x += vec.d_x;
93 d_y += vec.d_y;
94
95 return *this;
96 }
97
98 inline Vector2& operator-=(const Vector2& vec)
99 {
100 d_x -= vec.d_x;
101 d_y -= vec.d_y;
102
103 return *this;
104 }
105
106 inline Vector2 operator+(const Vector2& vec) const
107 {
108 return Vector2(d_x + vec.d_x, d_y + vec.d_y);
109 }
110
111 inline Vector2 operator-(const Vector2& vec) const
112 {
113 return Vector2(d_x - vec.d_x, d_y - vec.d_y);
114 }
115
116 inline Vector2 operator*(const Vector2& vec) const
117 {
118 return Vector2(d_x * vec.d_x, d_y * vec.d_y);
119 }
120
121 inline Vector2 operator/(const Vector2& vec) const
122 {
123 return Vector2(d_x / vec.d_x, d_y / vec.d_y);
124 }
125
126 inline Vector2 operator*(const T c) const
127 {
128 return Vector2(d_x * c, d_y * c);
129 }
130
131 inline Vector2& operator*=(const T c)
132 {
133 d_x *= c;
134 d_y *= c;
135
136 return *this;
137 }
138
139 inline Vector2 operator/(const T c) const
140 {
141 return Vector2(d_x / c, d_y / c);
142 }
143
144 inline bool operator==(const Vector2& vec) const
145 {
146 return ((d_x == vec.d_x) && (d_y == vec.d_y));
147 }
148
149 inline bool operator!=(const Vector2& vec) const
150 {
151 return !(operator==(vec));
152 }
153
157 inline friend std::ostream& operator << (std::ostream& s, const Vector2& v)
158 {
159 s << "CEGUI::Vector2<" << typeid(T).name() << ">(" << v.d_x << ", " << v.d_y << ")";
160 return s;
161 }
162
164 inline static Vector2 zero()
165 {
167 }
168
170 inline static Vector2 one()
171 {
173 }
174
176 inline static Vector2 one_x()
177 {
179 }
180
182 inline static Vector2 one_y()
183 {
185 }
186
187 T d_x;
188 T d_y;
189};
190
191// the main reason for this is to keep C++ API in sync with other languages
192typedef Vector2<float> Vector2f;
193
194// we need to allow UVector2 to be multiplied by floats, this is the most elegant way to do that
195inline Vector2<UDim> operator * (const Vector2<UDim>& v, const float c)
196{
197 return Vector2<UDim>(v.d_x * c, v.d_y * c);
198}
199
200typedef Vector2<UDim> UVector2;
201
214template<typename T>
216 public AllocatedObject<Vector3<T> >
217{
218public:
219 typedef T value_type;
220
221 inline Vector3()
222 {}
223
224 inline Vector3(const T x, const T y, const T z):
225 d_x(x),
226 d_y(y),
227 d_z(z)
228 {}
229
230 inline explicit Vector3(const Vector2<T>& v, const T z):
231 d_x(v.d_x),
232 d_y(v.d_y),
233 d_z(z)
234 {}
235
236 inline Vector3(const Vector3& v):
237 d_x(v.d_x),
238 d_y(v.d_y),
239 d_z(v.d_z)
240 {}
241
242 inline bool operator==(const Vector3& vec) const
243 {
244 return ((d_x == vec.d_x) && (d_y == vec.d_y) && (d_z == vec.d_z));
245 }
246
247 inline bool operator!=(const Vector3& vec) const
248 {
249 return !(operator==(vec));
250 }
251
252 inline Vector3 operator*(const T c) const
253 {
254 return Vector3(d_x * c, d_y * c, d_z * c);
255 }
256
257 inline Vector3 operator+(const Vector3& v) const
258 {
259 return Vector3(d_x + v.d_x, d_y + v.d_y, d_z + v.d_z);
260 }
261
262 inline Vector3 operator-(const Vector3& v) const
263 {
264 return Vector3(d_x - v.d_x, d_y - v.d_y, d_z - v.d_z);
265 }
266
270 inline friend std::ostream& operator << (std::ostream& s, const Vector3& v)
271 {
272 s << "CEGUI::Vector3<" << typeid(T).name() << ">(" << v.d_x << ", " << v.d_y << ", " << v.d_z << ")";
273 return s;
274 }
275
277 inline static Vector3 zero()
278 {
280 }
281
283 inline static Vector3 one()
284 {
286 }
287
289 inline static Vector3 one_x()
290 {
292 }
293
295 inline static Vector3 one_y()
296 {
298 }
299
301 inline static Vector3 one_z()
302 {
304 }
305
306 T d_x;
307 T d_y;
308 T d_z;
309};
310
311// the main reason for this is to keep C++ API in sync with other languages
312typedef Vector3<float> Vector3f;
313
314} // End of CEGUI namespace section
315
316#endif // end of guard _CEGUIVector_h_
Definition MemoryAllocatedObject.h:110
base class for properties able to do native set/get
Definition TypedProperty.h:50
Class used as a two dimensional vector (aka a Point)
Definition Vector.h:55
static Vector2 zero()
finger saving alias for Vector2(0, 0)
Definition Vector.h:164
static Vector2 one_x()
finger saving alias for Vector2(1, 0)
Definition Vector.h:176
static Vector2 one()
finger saving alias for Vector2(1, 1)
Definition Vector.h:170
friend std::ostream & operator<<(std::ostream &s, const Vector2 &v)
allows writing the vector2 to std ostream
Definition Vector.h:157
static Vector2 one_y()
finger saving alias for Vector2(0, 1)
Definition Vector.h:182
Class used as a three dimensional vector.
Definition Vector.h:217
static Vector3 one_x()
finger saving alias for Vector3(1, 0, 0)
Definition Vector.h:289
static Vector3 one()
finger saving alias for Vector3(1, 1, 1)
Definition Vector.h:283
static Vector3 one_z()
finger saving alias for Vector3(0, 0, 1)
Definition Vector.h:301
static Vector3 one_y()
finger saving alias for Vector3(0, 1, 0)
Definition Vector.h:295
friend std::ostream & operator<<(std::ostream &s, const Vector3 &v)
allows writing the vector3 to std ostream
Definition Vector.h:270
static Vector3 zero()
finger saving alias for Vector3(0, 0, 0)
Definition Vector.h:277
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1