Crazy Eddies GUI System  0.7.8
CEGUIVector.h
1 /***********************************************************************
2  filename: CEGUIVector.h
3  created: 14/3/2004
4  author: Paul D Turner
5 
6  purpose: Defines interfaces for Vector classes
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIVector_h_
31 #define _CEGUIVector_h_
32 
33 #include "CEGUIBase.h"
34 #include "CEGUISize.h"
35 
36 
37 // Start of CEGUI namespace section
38 namespace CEGUI
39 {
40 
45 class CEGUIEXPORT Vector2
46 {
47 public:
48  Vector2(void) {}
49  Vector2(float x, float y) : d_x(x), d_y(y) {}
50  Vector2(const Vector2& v) : d_x(v.d_x), d_y(v.d_y) {}
51 
52  Vector2& operator*=(const Vector2& vec)
53  {
54  d_x *= vec.d_x;
55  d_y *= vec.d_y;
56 
57  return *this;
58  }
59 
60  Vector2& operator/=(const Vector2& vec)
61  {
62  d_x /= vec.d_x;
63  d_y /= vec.d_y;
64 
65  return *this;
66  }
67 
68  Vector2& operator+=(const Vector2& vec)
69  {
70  d_x += vec.d_x;
71  d_y += vec.d_y;
72 
73  return *this;
74  }
75 
76  Vector2& operator-=(const Vector2& vec)
77  {
78  d_x -= vec.d_x;
79  d_y -= vec.d_y;
80 
81  return *this;
82  }
83 
84  Vector2 operator+(const Vector2& vec) const
85  {
86  return Vector2(d_x + vec.d_x, d_y + vec.d_y);
87  }
88 
89  Vector2 operator-(const Vector2& vec) const
90  {
91  return Vector2(d_x - vec.d_x, d_y - vec.d_y);
92  }
93 
94  Vector2 operator*(const Vector2& vec) const
95  {
96  return Vector2(d_x * vec.d_x, d_y * vec.d_y);
97  }
98 
99  Vector2 operator*(float c) const
100  {
101  return Vector2(d_x * c, d_y * c);
102  }
103 
104  bool operator==(const Vector2& vec) const
105  {
106  return ((d_x == vec.d_x) && (d_y == vec.d_y));
107  }
108 
109  bool operator!=(const Vector2& vec) const
110  {
111  return !(operator==(vec));
112  }
113 
114  Size asSize() const { return Size(d_x, d_y); }
115 
116  float d_x, d_y;
117 };
118 
123 typedef Vector2 Point;
124 
125 
130 class CEGUIEXPORT Vector3
131 {
132 public:
133  Vector3(void) {}
134  Vector3(float x, float y, float z) : d_x(x), d_y(y), d_z(z) {}
135  Vector3(const Vector3& v) : d_x(v.d_x), d_y(v.d_y), d_z(v.d_z) {}
136 
137  bool operator==(const Vector3& vec) const
138  {
139  return ((d_x == vec.d_x) && (d_y == vec.d_y) && (d_z == vec.d_z));
140  }
141 
142  bool operator!=(const Vector3& vec) const
143  {
144  return !(operator==(vec));
145  }
146 
147  Vector3 operator*(float c) const
148  {
149  return Vector3(d_x * c, d_y * c, d_z * c);
150  }
151 
152  Vector3 operator+(const Vector3& v) const
153  {
154  return Vector3(d_x + v.d_x, d_y + v.d_y, d_z + v.d_z);
155  }
156 
157  float d_x, d_y, d_z;
158 };
159 
160 } // End of CEGUI namespace section
161 
162 
163 #endif // end of guard _CEGUIVector_h_
164