1 ////////////////////////////////////////////////////////////
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
21 // 3. This notice may not be removed or altered from any source distribution.
23 ////////////////////////////////////////////////////////////
25 #ifndef SFML_VECTOR3_HPP
26 #define SFML_VECTOR3_HPP
31 ////////////////////////////////////////////////////////////
32 /// \brief Utility template class for manipulating
33 /// 3-dimensional vectors
35 ////////////////////////////////////////////////////////////
41 ////////////////////////////////////////////////////////////
42 /// \brief Default constructor
44 /// Creates a Vector3(0, 0, 0).
46 ////////////////////////////////////////////////////////////
49 ////////////////////////////////////////////////////////////
50 /// \brief Construct the vector from its coordinates
52 /// \param X X coordinate
53 /// \param Y Y coordinate
54 /// \param Z Z coordinate
56 ////////////////////////////////////////////////////////////
57 Vector3(T X, T Y, T Z);
59 ////////////////////////////////////////////////////////////
60 /// \brief Construct the vector from another type of vector
62 /// This constructor doesn't replace the copy constructor,
63 /// it's called only when U != T.
64 /// A call to this constructor will fail to compile if U
65 /// is not convertible to T.
67 /// \param vector Vector to convert
69 ////////////////////////////////////////////////////////////
71 explicit Vector3(const Vector3<U>& vector);
73 ////////////////////////////////////////////////////////////
75 ////////////////////////////////////////////////////////////
76 T x; ///< X coordinate of the vector
77 T y; ///< Y coordinate of the vector
78 T z; ///< Z coordinate of the vector
81 ////////////////////////////////////////////////////////////
83 /// \brief Overload of unary operator -
85 /// \param left Vector to negate
87 /// \return Memberwise opposite of the vector
89 ////////////////////////////////////////////////////////////
91 Vector3<T> operator -(const Vector3<T>& left);
93 ////////////////////////////////////////////////////////////
95 /// \brief Overload of binary operator +=
97 /// This operator performs a memberwise addition of both vectors,
98 /// and assigns the result to \a left.
100 /// \param left Left operand (a vector)
101 /// \param right Right operand (a vector)
103 /// \return Reference to \a left
105 ////////////////////////////////////////////////////////////
106 template <typename T>
107 Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right);
109 ////////////////////////////////////////////////////////////
111 /// \brief Overload of binary operator -=
113 /// This operator performs a memberwise subtraction of both vectors,
114 /// and assigns the result to \a left.
116 /// \param left Left operand (a vector)
117 /// \param right Right operand (a vector)
119 /// \return Reference to \a left
121 ////////////////////////////////////////////////////////////
122 template <typename T>
123 Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right);
125 ////////////////////////////////////////////////////////////
127 /// \brief Overload of binary operator +
129 /// \param left Left operand (a vector)
130 /// \param right Right operand (a vector)
132 /// \return Memberwise addition of both vectors
134 ////////////////////////////////////////////////////////////
135 template <typename T>
136 Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right);
138 ////////////////////////////////////////////////////////////
140 /// \brief Overload of binary operator -
142 /// \param left Left operand (a vector)
143 /// \param right Right operand (a vector)
145 /// \return Memberwise subtraction of both vectors
147 ////////////////////////////////////////////////////////////
148 template <typename T>
149 Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right);
151 ////////////////////////////////////////////////////////////
153 /// \brief Overload of binary operator *
155 /// \param left Left operand (a vector)
156 /// \param right Right operand (a scalar value)
158 /// \return Memberwise multiplication by \a right
160 ////////////////////////////////////////////////////////////
161 template <typename T>
162 Vector3<T> operator *(const Vector3<T>& left, T right);
164 ////////////////////////////////////////////////////////////
166 /// \brief Overload of binary operator *
168 /// \param left Left operand (a scalar value)
169 /// \param right Right operand (a vector)
171 /// \return Memberwise multiplication by \a left
173 ////////////////////////////////////////////////////////////
174 template <typename T>
175 Vector3<T> operator *(T left, const Vector3<T>& right);
177 ////////////////////////////////////////////////////////////
179 /// \brief Overload of binary operator *=
181 /// This operator performs a memberwise multiplication by \a right,
182 /// and assigns the result to \a left.
184 /// \param left Left operand (a vector)
185 /// \param right Right operand (a scalar value)
187 /// \return Reference to \a left
189 ////////////////////////////////////////////////////////////
190 template <typename T>
191 Vector3<T>& operator *=(Vector3<T>& left, T right);
193 ////////////////////////////////////////////////////////////
195 /// \brief Overload of binary operator /
197 /// \param left Left operand (a vector)
198 /// \param right Right operand (a scalar value)
200 /// \return Memberwise division by \a right
202 ////////////////////////////////////////////////////////////
203 template <typename T>
204 Vector3<T> operator /(const Vector3<T>& left, T right);
206 ////////////////////////////////////////////////////////////
208 /// \brief Overload of binary operator /=
210 /// This operator performs a memberwise division by \a right,
211 /// and assigns the result to \a left.
213 /// \param left Left operand (a vector)
214 /// \param right Right operand (a scalar value)
216 /// \return Reference to \a left
218 ////////////////////////////////////////////////////////////
219 template <typename T>
220 Vector3<T>& operator /=(Vector3<T>& left, T right);
222 ////////////////////////////////////////////////////////////
224 /// \brief Overload of binary operator ==
226 /// This operator compares strict equality between two vectors.
228 /// \param left Left operand (a vector)
229 /// \param right Right operand (a vector)
231 /// \return True if \a left is equal to \a right
233 ////////////////////////////////////////////////////////////
234 template <typename T>
235 bool operator ==(const Vector3<T>& left, const Vector3<T>& right);
237 ////////////////////////////////////////////////////////////
239 /// \brief Overload of binary operator !=
241 /// This operator compares strict difference between two vectors.
243 /// \param left Left operand (a vector)
244 /// \param right Right operand (a vector)
246 /// \return True if \a left is not equal to \a right
248 ////////////////////////////////////////////////////////////
249 template <typename T>
250 bool operator !=(const Vector3<T>& left, const Vector3<T>& right);
252 #include <SFML/System/Vector3.inl>
254 // Define the most common types
255 typedef Vector3<int> Vector3i;
256 typedef Vector3<float> Vector3f;
261 #endif // SFML_VECTOR3_HPP
264 ////////////////////////////////////////////////////////////
265 /// \class sf::Vector3
268 /// sf::Vector3 is a simple class that defines a mathematical
269 /// vector with three coordinates (x, y and z). It can be used to
270 /// represent anything that has three dimensions: a size, a point,
273 /// The template parameter T is the type of the coordinates. It
274 /// can be any type that supports arithmetic operations (+, -, /, *)
275 /// and comparisons (==, !=), for example int or float.
277 /// You generally don't have to care about the templated form (sf::Vector3<T>),
278 /// the most common specializations have special typedefs:
279 /// \li sf::Vector3<float> is sf::Vector3f
280 /// \li sf::Vector3<int> is sf::Vector3i
282 /// The sf::Vector3 class has a small and simple interface, its x and y members
283 /// can be accessed directly (there are no accessors like setX(), getX()) and it
284 /// contains no mathematical function like dot product, cross product, length, etc.
288 /// sf::Vector3f v1(16.5f, 24.f, -8.2f);
293 /// sf::Vector3f v2 = v1 * 5.f;
297 /// bool different = (v2 != v3);
300 /// Note: for 2-dimensional vectors, see sf::Vector2.
302 ////////////////////////////////////////////////////////////