36 | | value_type _v[4]; // a four-vector |
37 | | |
38 | | inline Quat() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=1.0; } |
39 | | |
40 | | inline Quat( value_type x, value_type y, value_type z, value_type w ) |
| 36 | value_type _v[4]; // a four-vector |
| 37 | |
| 38 | inline Quat() { _v[0]=0.0; _v[1]=0.0; _v[2]=0.0; _v[3]=1.0; } |
| 39 | |
| 40 | inline Quat( value_type x, value_type y, value_type z, value_type w ) |
103 | | Methods to access data members |
104 | | ---------------------------------- */ |
105 | | |
106 | | inline Vec4d asVec4() const |
107 | | { |
108 | | return Vec4d(_v[0], _v[1], _v[2], _v[3]); |
109 | | } |
110 | | |
111 | | inline Vec3d asVec3() const |
112 | | { |
113 | | return Vec3d(_v[0], _v[1], _v[2]); |
114 | | } |
| 103 | Methods to access data members |
| 104 | ---------------------------------- */ |
| 105 | |
| 106 | inline Vec4d asVec4() const |
| 107 | { |
| 108 | return Vec4d(_v[0], _v[1], _v[2], _v[3]); |
| 109 | } |
| 110 | |
| 111 | inline Vec3d asVec3() const |
| 112 | { |
| 113 | return Vec3d(_v[0], _v[1], _v[2]); |
| 114 | } |
166 | | /* ------------------------------------------------------------- |
167 | | BASIC ARITHMETIC METHODS |
168 | | Implemented in terms of Vec4s. Some Vec4 operators, e.g. |
169 | | operator* are not appropriate for quaternions (as |
170 | | mathematical objects) so they are implemented differently. |
171 | | Also define methods for conjugate and the multiplicative inverse. |
172 | | ------------------------------------------------------------- */ |
173 | | /// Multiply by scalar |
| 166 | /* ------------------------------------------------------------- |
| 167 | BASIC ARITHMETIC METHODS |
| 168 | Implemented in terms of Vec4s. Some Vec4 operators, e.g. |
| 169 | operator* are not appropriate for quaternions (as |
| 170 | mathematical objects) so they are implemented differently. |
| 171 | Also define methods for conjugate and the multiplicative inverse. |
| 172 | ------------------------------------------------------------- */ |
| 173 | /// Multiply by scalar |
189 | | /// Binary multiply |
190 | | inline const Quat operator*(const Quat& rhs) const |
191 | | { |
192 | | return Quat( rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] - rhs._v[2]*_v[1], |
193 | | rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0], |
194 | | rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3], |
195 | | rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2] ); |
196 | | } |
197 | | |
198 | | /// Unary multiply |
199 | | inline Quat& operator*=(const Quat& rhs) |
200 | | { |
201 | | value_type x = rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] - rhs._v[2]*_v[1]; |
202 | | value_type y = rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0]; |
203 | | value_type z = rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3]; |
204 | | _v[3] = rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2]; |
205 | | |
206 | | _v[2] = z; |
207 | | _v[1] = y; |
208 | | _v[0] = x; |
209 | | |
210 | | return (*this); // enable nesting |
211 | | } |
212 | | |
213 | | /// Divide by scalar |
| 189 | /// Binary multiply |
| 190 | inline const Quat operator*(const Quat& rhs) const |
| 191 | { |
| 192 | return Quat( rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] - rhs._v[2]*_v[1], |
| 193 | rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0], |
| 194 | rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3], |
| 195 | rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2] ); |
| 196 | } |
| 197 | |
| 198 | /// Unary multiply |
| 199 | inline Quat& operator*=(const Quat& rhs) |
| 200 | { |
| 201 | value_type x = rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] - rhs._v[2]*_v[1]; |
| 202 | value_type y = rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0]; |
| 203 | value_type z = rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3]; |
| 204 | _v[3] = rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2]; |
| 205 | |
| 206 | _v[2] = z; |
| 207 | _v[1] = y; |
| 208 | _v[0] = x; |
| 209 | |
| 210 | return (*this); // enable nesting |
| 211 | } |
| 212 | |
| 213 | /// Divide by scalar |
231 | | /// Binary divide |
232 | | inline const Quat operator/(const Quat& denom) const |
233 | | { |
234 | | return ( (*this) * denom.inverse() ); |
235 | | } |
236 | | |
237 | | /// Unary divide |
238 | | inline Quat& operator/=(const Quat& denom) |
239 | | { |
240 | | (*this) = (*this) * denom.inverse(); |
241 | | return (*this); // enable nesting |
242 | | } |
243 | | |
244 | | /// Binary addition |
| 231 | /// Binary divide |
| 232 | inline const Quat operator/(const Quat& denom) const |
| 233 | { |
| 234 | return ( (*this) * denom.inverse() ); |
| 235 | } |
| 236 | |
| 237 | /// Unary divide |
| 238 | inline Quat& operator/=(const Quat& denom) |
| 239 | { |
| 240 | (*this) = (*this) * denom.inverse(); |
| 241 | return (*this); // enable nesting |
| 242 | } |
| 243 | |
| 244 | /// Binary addition |
311 | | Set a quaternion which will perform a rotation of an |
312 | | angle around the axis given by the vector (x,y,z). |
313 | | Should be written to also accept an angle and a Vec3? |
314 | | |
315 | | Define Spherical Linear interpolation method also |
316 | | |
317 | | Not inlined - see the Quat.cpp file for implementation |
318 | | -------------------------------------------------------- */ |
| 311 | Set a quaternion which will perform a rotation of an |
| 312 | angle around the axis given by the vector (x,y,z). |
| 313 | Should be written to also accept an angle and a Vec3? |
| 314 | |
| 315 | Define Spherical Linear interpolation method also |
| 316 | |
| 317 | Not inlined - see the Quat.cpp file for implementation |
| 318 | -------------------------------------------------------- */ |