]> git.sesse.net Git - casparcg/blob - SFML-1.6/include/SFML/System/Vector3.inl
(no commit message)
[casparcg] / SFML-1.6 / include / SFML / System / Vector3.inl
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\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
8 //\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
12 //\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
17 //\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
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 \r
26 ////////////////////////////////////////////////////////////\r
27 /// Default constructor\r
28 ////////////////////////////////////////////////////////////\r
29 template <typename T>\r
30 Vector3<T>::Vector3() :\r
31 x(0),\r
32 y(0),\r
33 z(0)\r
34 {\r
35 \r
36 }\r
37 \r
38 \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
44 x(X),\r
45 y(Y),\r
46 z(Z)\r
47 {\r
48 \r
49 }\r
50 \r
51 \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
57 {\r
58     return Vector3<T>(-V.x, -V.y, -V.z);\r
59 }\r
60 \r
61 \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
67 {\r
68     V1.x += V2.x;\r
69     V1.y += V2.y;\r
70     V1.z += V2.z;\r
71 \r
72     return V1;\r
73 }\r
74 \r
75 \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
81 {\r
82     V1.x -= V2.x;\r
83     V1.y -= V2.y;\r
84     V1.z -= V2.z;\r
85 \r
86     return V1;\r
87 }\r
88 \r
89 \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
95 {\r
96     return Vector3<T>(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z);\r
97 }\r
98 \r
99 \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
105 {\r
106     return Vector3<T>(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z);\r
107 }\r
108 \r
109 \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
115 {\r
116     return Vector3<T>(V.x * X, V.y * X, V.z * X);\r
117 }\r
118 \r
119 \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
125 {\r
126     return Vector3<T>(V.x * X, V.y * X, V.z * X);\r
127 }\r
128 \r
129 \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
135 {\r
136     V.x *= X;\r
137     V.y *= X;\r
138     V.z *= X;\r
139 \r
140     return V;\r
141 }\r
142 \r
143 \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
149 {\r
150     return Vector3<T>(V.x / X, V.y / X, V.z / X);\r
151 }\r
152 \r
153 \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
159 {\r
160     V.x /= X;\r
161     V.y /= X;\r
162     V.z /= X;\r
163 \r
164     return V;\r
165 }\r
166 \r
167 \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
173 {\r
174     return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z);\r
175 }\r
176 \r
177 \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
183 {\r
184     return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z);\r
185 }\r