]>
Dogcows Code - chaz/yoink/blob - src/moof/cml/mathlib/quaternion_basis.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
13 #ifndef quaternion_basis_h
14 #define quaternion_basis_h
16 #include <cml/mathlib/checking.h>
18 /* Functions for getting the basis vectors of a quaternion rotation. */
22 /** Get the i'th basis vector of a quaternion rotation */
23 template < class QuatT
> vector
< typename
QuatT::value_type
, fixed
<3> >
24 quaternion_get_basis_vector(const QuatT
& q
, size_t i
)
26 typedef QuatT quaternion_type
;
27 typedef typename
quaternion_type::value_type value_type
;
28 typedef typename
quaternion_type::order_type order_type
;
29 typedef vector
< value_type
, fixed
<3> > vector_type
;
33 detail::CheckIndex3(i
);
36 cyclic_permutation(i
, i
, j
, k
);
38 /* @todo: Clean this up. */
39 const size_t W
= order_type::W
;
40 const size_t I
= order_type::X
+ i
;
41 const size_t J
= order_type::X
+ j
;
42 const size_t K
= order_type::X
+ k
;
44 value_type j2
= q
[J
] + q
[J
];
45 value_type k2
= q
[K
] + q
[K
];
47 /* @todo: use set_permuted() for the following when available. */
50 result
[i
] = value_type(1) - q
[J
] * j2
- q
[K
] * k2
;
51 result
[j
] = q
[I
] * j2
+ q
[W
] * k2
;
52 result
[k
] = q
[I
] * k2
- q
[W
] * j2
;
56 /** Get the x basis vector of a quaternion rotation */
57 template < class QuatT
> vector
< typename
QuatT::value_type
, fixed
<3> >
58 quaternion_get_x_basis_vector(const QuatT
& q
) {
59 return quaternion_get_basis_vector(q
,0);
62 /** Get the y basis vector of a quaternion rotation */
63 template < class QuatT
> vector
< typename
QuatT::value_type
, fixed
<3> >
64 quaternion_get_y_basis_vector(const QuatT
& q
) {
65 return quaternion_get_basis_vector(q
,1);
68 /** Get the z basis vector of a quaternion rotation */
69 template < class QuatT
> vector
< typename
QuatT::value_type
, fixed
<3> >
70 quaternion_get_z_basis_vector(const QuatT
& q
) {
71 return quaternion_get_basis_vector(q
,2);
74 /** Get the basis vectors of a quaternion rotation */
75 template < class QuatT
, typename E
, class A
> void
76 quaternion_get_basis_vectors(
82 x
= quaternion_get_x_basis_vector(q
);
83 y
= quaternion_get_y_basis_vector(q
);
84 z
= quaternion_get_z_basis_vector(q
);
This page took 0.038692 seconds and 4 git commands to generate.