CMSC23700 Common Code Library
Support code for CS23700 programming projects
cs237-quat.hxx
Go to the documentation of this file.
1 
8 /*
9  * COPYRIGHT (c) 2015 John Reppy (http://cs.uchicago.edu/~jhr)
10  * All rights reserved.
11  */
12 
13 #ifndef _CS237_QUAT_HXX_
14 #define _CS237_QUAT_HXX_
15 
16 #ifndef _CS237_HXX_
17 #error "c237-quat.hxx should not be included directly"
18 #endif
19 
20 namespace cs237 {
21 
22  namespace __detail {
23 
25  template <typename T>
26  struct quat {
27  T x, y, z, w;
28 
29  quat () : x(T(0)), y(T(0)), z(T(0)), w(T(0)) { }
30  quat (quat const &q) : x(q.x), y(q.y), z(q.z), w(q.w) { }
31  explicit quat (T xx, T yy, T zz) : x(xx), y(yy), z(zz), w(T(0)) { }
32  explicit quat (T xx, T yy, T zz, T ww) : x(xx), y(yy), z(zz), w(ww) { }
33  explicit quat (vec3<T> const &v) : x(v.x), y(v.y), z(v.z), w(T(0)) { }
34  explicit quat (vec3<T> const &v, T ww) : x(v.x), y(v.y), z(v.z), w(ww) { }
35 
37  explicit quat (T angle, vec3<T> const &axis);
38 
39  T & operator[] (unsigned int const &i);
40  T const & operator[] (unsigned int const &i) const;
41 
42  quat & operator= (quat const &v);
43 
44  quat & operator+= (quat const &v);
45 
46  quat & operator-= (quat const &v);
47 
48  quat & operator*= (T const &s);
49  quat & operator*= (quat const &q);
50  quat & operator*= (vec3<T> const &v);
51 
52  quat & operator/= (T const &s);
53 
54  quat conjugate () const;
55  quat inverse () const;
56 
57  T length () const;
58 
60  quat & normalize ();
61 
64  vec3<T> rotate (vec3<T> const &v) const;
65 
67  mat3x3<T> toMat3x3 () const;
68 
70  mat4x4<T> toMat4x4 () const;
71  };
72 
76  template <typename T>
77  std::ostream& operator<< (std::ostream& s, quat<T> const &v);
78 
79  } /* _namespace __detail */
80 
85 
86 } /* namespace cs237 */
87 
88 #endif /* !_CS237_QUAT_HXX_ */
quat(quat const &q)
Definition: cs237-quat.hxx:30
quat(T xx, T yy, T zz)
Definition: cs237-quat.hxx:31
quat(T xx, T yy, T zz, T ww)
Definition: cs237-quat.hxx:32
__detail::quat< double > quatd
Double-precision quaternions.
Definition: cs237-quat.hxx:84
T w
Definition: cs237-quat.hxx:27
quat & operator=(quat const &v)
Definition: cs237-quat.inl:57
mat3x3< T > toMat3x3() const
return the 3x3 linear rotation matrix represented by this quaternion
quat & operator*=(T const &s)
Definition: cs237-quat.inl:104
quat & operator+=(quat const &v)
Definition: cs237-quat.inl:82
T y
Definition: cs237-quat.hxx:27
quat & operator-=(quat const &v)
Definition: cs237-quat.inl:93
template class for quaternions
Definition: cs237-quat.hxx:26
T z
Definition: cs237-quat.hxx:27
T x
Definition: cs237-quat.hxx:27
quat & normalize()
normalize this quaternion to unit length
Definition: cs237-quat.inl:163
mat4x4< T > toMat4x4() const
return the 3x3 affine rotation matrix represented by this quaternion
quat & operator/=(T const &s)
Definition: cs237-quat.inl:133
T length() const
Definition: cs237-quat.inl:157
template class for 3x3 matrices
Definition: cs237-mat3x3.hxx:26
T & operator[](unsigned int const &i)
Definition: cs237-quat.inl:68
__detail::quat< float > quatf
Single-precision quaternions.
Definition: cs237-quat.hxx:82
quat(vec3< T > const &v, T ww)
Definition: cs237-quat.hxx:34
Definition: cs237-aabb.hxx:18
template class for 4x4 matrices
Definition: cs237-mat4x4.hxx:26
template class for three-element vectors
Definition: cs237-types.hxx:26
vec3< T > rotate(vec3< T > const &v) const
Definition: cs237-quat.inl:169
quat()
Definition: cs237-quat.hxx:29
quat(vec3< T > const &v)
Definition: cs237-quat.hxx:33
quat inverse() const
Definition: cs237-quat.inl:150
quat conjugate() const
Definition: cs237-quat.inl:144