1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
26 ////////////////////////////////////////////////////////////
\r
27 /// Default constructor
\r
28 ////////////////////////////////////////////////////////////
\r
29 template <typename T>
\r
30 Vector3<T>::Vector3() :
\r
39 ////////////////////////////////////////////////////////////
\r
40 /// Construct the color from its coordinates
\r
41 ////////////////////////////////////////////////////////////
\r
42 template <typename T>
\r
43 Vector3<T>::Vector3(T X, T Y, T Z) :
\r
52 ////////////////////////////////////////////////////////////
\r
53 /// Operator - overload ; returns the opposite of a vector
\r
54 ////////////////////////////////////////////////////////////
\r
55 template <typename T>
\r
56 Vector3<T> operator -(const Vector3<T>& V)
\r
58 return Vector3<T>(-V.x, -V.y, -V.z);
\r
62 ////////////////////////////////////////////////////////////
\r
63 /// Operator += overload ; add two vectors and assign to the first op
\r
64 ////////////////////////////////////////////////////////////
\r
65 template <typename T>
\r
66 Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2)
\r
76 ////////////////////////////////////////////////////////////
\r
77 /// Operator -= overload ; subtract two vectors and assign to the first op
\r
78 ////////////////////////////////////////////////////////////
\r
79 template <typename T>
\r
80 Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2)
\r
90 ////////////////////////////////////////////////////////////
\r
91 /// Operator + overload ; adds two vectors
\r
92 ////////////////////////////////////////////////////////////
\r
93 template <typename T>
\r
94 Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2)
\r
96 return Vector3<T>(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z);
\r
100 ////////////////////////////////////////////////////////////
\r
101 /// Operator - overload ; subtracts two vectors
\r
102 ////////////////////////////////////////////////////////////
\r
103 template <typename T>
\r
104 Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2)
\r
106 return Vector3<T>(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z);
\r
110 ////////////////////////////////////////////////////////////
\r
111 /// Operator * overload ; multiply a vector by a scalar value
\r
112 ////////////////////////////////////////////////////////////
\r
113 template <typename T>
\r
114 Vector3<T> operator *(const Vector3<T>& V, T X)
\r
116 return Vector3<T>(V.x * X, V.y * X, V.z * X);
\r
120 ////////////////////////////////////////////////////////////
\r
121 /// Operator * overload ; multiply a scalar value by a vector
\r
122 ////////////////////////////////////////////////////////////
\r
123 template <typename T>
\r
124 Vector3<T> operator *(T X, const Vector3<T>& V)
\r
126 return Vector3<T>(V.x * X, V.y * X, V.z * X);
\r
130 ////////////////////////////////////////////////////////////
\r
131 /// Operator *= overload ; multiply-assign a vector by a scalar value
\r
132 ////////////////////////////////////////////////////////////
\r
133 template <typename T>
\r
134 Vector3<T>& operator *=(Vector3<T>& V, T X)
\r
144 ////////////////////////////////////////////////////////////
\r
145 /// Operator / overload ; divide a vector by a scalar value
\r
146 ////////////////////////////////////////////////////////////
\r
147 template <typename T>
\r
148 Vector3<T> operator /(const Vector3<T>& V, T X)
\r
150 return Vector3<T>(V.x / X, V.y / X, V.z / X);
\r
154 ////////////////////////////////////////////////////////////
\r
155 /// Operator /= overload ; divide-assign a vector by a scalar value
\r
156 ////////////////////////////////////////////////////////////
\r
157 template <typename T>
\r
158 Vector3<T>& operator /=(Vector3<T>& V, T X)
\r
168 ////////////////////////////////////////////////////////////
\r
169 /// Operator == overload ; compares the equality of two vectors
\r
170 ////////////////////////////////////////////////////////////
\r
171 template <typename T>
\r
172 bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2)
\r
174 return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z);
\r
178 ////////////////////////////////////////////////////////////
\r
179 /// Operator != overload ; compares the difference of two vectors
\r
180 ////////////////////////////////////////////////////////////
\r
181 template <typename T>
\r
182 bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2)
\r
184 return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z);
\r