]> Dogcows Code - chaz/yoink/blob - src/cml/quaternion/quaternion_print.h
beginnings of scene rendering
[chaz/yoink] / src / cml / quaternion / quaternion_print.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief
11 */
12
13 #ifndef quaternion_print_h
14 #define quaternion_print_h
15
16 #include <iostream>
17
18 namespace cml {
19
20 /* NOTE: Made 'plain' quaternion output the default (Jesse) */
21
22 /* #if !defined(CML_PLAIN_QUATERNION_OUTPUT) */
23 #if defined(CML_COMPLEX_QUATERNION_OUTPUT)
24
25 template<typename E, class AT, class CT> std::ostream&
26 operator<<(std::ostream& os, const cml::quaternion<E,AT,scalar_first,CT>& q)
27 {
28 os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]);
29 os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "i";
30 os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "j";
31 os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]) << "k";
32 return os;
33 }
34
35 template<typename E, class AT, class CT> std::ostream&
36 operator<<(std::ostream& os, const cml::quaternion<E,AT,vector_first,CT>& q)
37 {
38 os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]) << "i";
39 os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "j";
40 os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "k";
41 os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]);
42 return os;
43 }
44
45 #else
46
47 /** Output a quaternion to a std::ostream. */
48 template<typename E, class AT, class OT, typename CT> std::ostream&
49 operator<<(std::ostream& os, const cml::quaternion<E,AT,OT,CT>& q)
50 {
51 os << "[";
52 for (size_t i = 0; i < 4; ++i) {
53 os << " " << q[i];
54 }
55 os << " ]";
56 return os;
57 }
58
59 #endif
60
61 /** Output a quaternion expression to a std::ostream. */
62 template< class XprT > inline std::ostream&
63 operator<<(std::ostream& os, const et::QuaternionXpr<XprT>& q)
64 {
65 typedef typename et::QuaternionXpr<XprT>::result_type quaternion_type;
66
67 os << quaternion_type(q);
68 /* XXX This temporary can be removed by templating the stream insertion
69 * operators above.
70 */
71
72 return os;
73 }
74
75 } // namespace cml
76
77 #endif
78
79 // -------------------------------------------------------------------------
80 // vim:ft=cpp
This page took 0.031484 seconds and 4 git commands to generate.