API  0.0.2
Défini un objet Vector et les accès à l’interface wxWidgets.
Vector.h
Aller à la documentation de ce fichier.
1 
8 #ifndef API_VECTOR_H
9 #define API_VECTOR_H
10 
11 #include <iostream>
12 
13 namespace API
14 {
15  namespace Math
16  {
17  template <typename T>
18  struct Vector3
19  {
20  using component_type = T;
21  T x, y, z;
22 
23  Vector3();
24  Vector3(T inX, T inY, T inZ);
25 
26  Vector3(const API::Math::Vector3<T> &inVector) :
27  x(inVector.x),
28  y(inVector.y),
29  z(inVector.z)
30  {}
31 
32  Vector3(const T inScaler) :
33  x(inScaler),
34  y(inScaler),
35  z(inScaler)
36  {}
37 
38  virtual ~Vector3();
39 
41  virtual void swap(Vector3<T> &inVector)
42  {
43  std::swap(x, inVector.x);
44  std::swap(y, inVector.y);
45  std::swap(z, inVector.z);
46  }
47 
51  virtual Vector3<T>& operator = (const Vector3<T> &inVector)
52  {
53  this->x = inVector.x;
54  this->y = inVector.y;
55  this->z = inVector.z;
56 
57  return *this;
58  }
59 
60  virtual Vector3<T>& operator = (const T inScalar)
61  {
62  this->x = inScalar;
63  this->y = inScalar;
64  this->z = inScalar;
65 
66  return *this;
67  }
68 
69  virtual bool operator == (const Vector3<T> &inVector) const
70  {
71  return x == inVector.x && y == inVector.y && z == inVector.z;
72  }
73 
74  virtual bool operator != (const Vector3<T> &inVector) const
75  {
76  return x != inVector.x || y != inVector.y || z != inVector.z;
77  }
78 
79  // arithmetic operations
80  virtual Vector3<T> operator + (const Vector3<T> &inVector) const
81  {
82  return Vector3<T>(this->x + inVector.x, this->y + inVector.y, this->z + inVector.z);
83  }
84 
85  virtual Vector3<T> operator - (const Vector3<T>& inVector) const
86  {
87  return Vector3<T>(this->x - inVector.x, this->y - inVector.y, this->z - inVector.z);
88  }
89 
90  Vector3<T> operator * (const T inScalar) const
91  {
92  return Vector3<T>(this->x * inScalar, this->y * inScalar, this->z * inScalar);
93  }
94 
95  virtual Vector3<T> operator * (const Vector3<T> &inVector) const
96  {
97  return Vector3<T>(inVector.x * this->x, inVector.y * this->y, inVector.y * this->z);
98  }
99 
100  virtual const Vector3<T> & operator + () const
101  {
102  return *this;
103  }
104 
105  Vector3<T> operator - () const
106  {
107  return Vector3<T>(-this->x, -this->y, -this->z);
108  }
109 
110  inline friend Vector3<T> operator * (const T inScalar, const Vector3<T> &inVector)
111  {
112  return Vector3<T>(inScalar * inVector.x, inScalar * inVector.y, inScalar * inVector.z);
113  }
114 
115  inline friend Vector3<T> operator + (const Vector3<T> &inVector, const T inValue)
116  {
117  return Vector3<T>(inVector.x + inValue, inVector.y + inValue, inVector.z + inValue);
118  }
119 
120  inline friend Vector3<T> operator + (const T inValue, const Vector3<T> &inVector)
121  {
122  return Vector3<T>(inValue + inVector.x, inValue + inVector.y, inValue + inVector.z);
123  }
124 
125  inline friend Vector3<T> operator - (const Vector3<T> &inVector, T inValue)
126  {
127  return Vector3<T>(inVector.x - inValue, inVector.y - inValue, inVector.z - inValue);
128  }
129 
130  inline friend Vector3<T> operator - (const T inValue, const Vector3<T> &inVector)
131  {
132  return Vector3<T>(inValue - inVector.x, inValue - inVector.y, inValue - inVector.z);
133  }
134 
135  // arithmetic updates
136  virtual Vector3<T>& operator += (const Vector3<T> &inVector)
137  {
138  this->x += inVector.x;
139  this->y += inVector.y;
140  this->z += inVector.z;
141 
142  return *this;
143  }
144 
145  virtual Vector3<T>& operator -= (const Vector3<T> &inVector)
146  {
147  this->x -= inVector.x;
148  this->y -= inVector.y;
149  this->z -= inVector.z;
150 
151  return *this;
152  }
153 
154  virtual Vector3<T>& operator *= (const T inScalar)
155  {
156  this->x *= inScalar;
157  this->y *= inScalar;
158  this->z *= inScalar;
159 
160  return *this;
161  }
162 
163  virtual Vector3<T>& operator += (const T inScalar)
164  {
165  this->x += inScalar;
166  this->y += inScalar;
167  this->z += inScalar;
168 
169  return *this;
170  }
171 
172  virtual Vector3<T>& operator -= (const T inScalar)
173  {
174  this->x -= inScalar;
175  this->y -= inScalar;
176  this->z -= inScalar;
177 
178  return *this;
179  }
180 
181  virtual Vector3<T>& operator *= (const Vector3<T> &inVector)
182  {
183  this->x *= inVector.x;
184  this->y *= inVector.y;
185  this->z *= inVector.z;
186 
187  return *this;
188  }
189 
190  inline Vector3<T>& operator /= (const Vector3<T> &inVector)
191  {
192  this->x /= inVector.x;
193  this->y /= inVector.y;
194  this->z /= inVector.z;
195 
196  return *this;
197  }
198 
199  virtual T dotProduct(const Vector3 &inVec) const;
200 
201  friend std::ostream& operator << (std::ostream &inOStream, const Vector3 &inVector)
202  {
203  inOStream << inVector.x << ", " << inVector.y << ", " << inVector.z;
204  return inOStream;
205  }
206  };
207  }
208 }
209 
210 #include "Vector.tpp"
211 
212 #endif // API_VECTOR_H
virtual Vector3< T > & operator=(const Vector3< T > &inVector)
Definition: Vector.h:51
virtual void swap(Vector3< T > &inVector)
Definition: Vector.h:41
Definition: Vector.h:18
Definition: Vector.h:13