Debian Codegraph @

3rdparty/xspublic/xstypes/xseuler.h

raw
1
2 // Copyright (c) 2003-2019 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32
33 #ifndef XSEULER_H
34 #define XSEULER_H
35
36 #include "xsmath.h"
37 #include <math.h>
38
39 #ifdef __cplusplus
40 #include "xsvector.h"
41 extern "C" {
42 #endif
43 #ifndef __cplusplus
44 #define XSEULER_INITIALIZER { { { XsMath_zero,XsMath_zero,XsMath_zero } } }
45 struct XsVector;
46 #endif
47
48 struct XsEuler;
49 struct XsQuaternion;
50 struct XsMatrix;
51
52 XSTYPES_DLL_API void XsEuler_destruct(struct XsEuler* thisPtr);
53 XSTYPES_DLL_API int XsEuler_empty(const struct XsEuler* thisPtr);
54 XSTYPES_DLL_API void XsEuler_fromQuaternion(struct XsEuler* thisPtr, const struct XsQuaternion* quat);
55
56 #ifdef __cplusplus
57 } // extern "C"
58 #endif
59
60 struct XsEuler {
61 #ifdef __cplusplus
62 //! \brief Constructor that creates an Euler object with all angles 0
63 inline XsEuler() : m_x(XsMath_zero), m_y(XsMath_zero), m_z(XsMath_zero) {}
64 //! \brief Constructor that creates an Euler object the specified angles
65 inline XsEuler(XsReal x_, XsReal y_, XsReal z_) : m_x(x_), m_y(y_), m_z(z_) {}
66 //! \brief Constructor that creates an Euler object from \a other
67 inline XsEuler(const XsEuler& other) : m_x(other.m_x), m_y(other.m_y), m_z(other.m_z) {}
68 //! \brief Constructor that creates an Euler object from \a other
69 inline explicit XsEuler(const XsVector& other) : m_x(other[0]), m_y(other[1]), m_z(other[2]) {}
70
71 //! \brief \copybrief XsEuler_fromQuaternion
72 inline explicit XsEuler(const XsQuaternion& q)
73 {
74 XsEuler_fromQuaternion(this, &q);
75 }
76
77 //! \brief Assigns the \a other XsEuler object to this one
78 inline XsEuler& operator=(const XsEuler& other)
79 {
80 m_x = other.m_x;
81 m_y = other.m_y;
82 m_z = other.m_z;
83 return *this;
84 }
85
86 //! \brief Returns the \a index'th euler angle in the object
87 inline XsReal operator[](XsSize index) const
88 {
89 assert (index <= 2);
90 return m_data[index];
91 }
92
93 //! \brief Returns a reference to the \a index'th euler angle in the object
94 inline XsReal &operator[](XsSize index)
95 {
96 assert (index <= 2);
97 return m_data[index];
98 }
99
100 //! \brief Returns true if all angles in this object are zero
101 inline bool empty() const
102 {
103 return m_x == XsMath_zero && m_y == XsMath_zero && m_z == XsMath_zero;
104 }
105
106 //! \brief Return a const pointer to the internal data
107 inline const XsReal* data() const
108 {
109 return m_data;
110 }
111
112 //! \brief \copybrief XsEuler_fromQuaternion
113 inline XsEuler& fromQuaternion(const XsQuaternion& quat)
114 {
115 XsEuler_fromQuaternion(this, &quat);
116 return *this;
117 }
118
119 /*! \brief Returns true if the values in \a other are exactly equal to this
120 */
121 inline bool operator == (const XsEuler& other) const
122 {
123 return m_roll == other.m_roll && m_pitch == other.m_pitch && m_yaw == other.m_yaw;
124 }
125
126 /*! \brief Returns true if the values in \a other are different from this
127 */
128 inline bool operator != (const XsEuler& other) const
129 {
130 return m_roll != other.m_roll || m_pitch != other.m_pitch || m_yaw != other.m_yaw;
131 }
132
133 //! \brief Returns the roll or x value
134 inline XsReal roll() const { return m_roll; }
135 //! \brief Returns the pitch or y value
136 inline XsReal pitch() const { return m_pitch; }
137 //! \brief Returns the yaw or z value
138 inline XsReal yaw() const { return m_yaw; }
139
140 //! \brief Returns the x or roll value
141 inline XsReal x() const { return m_x; }
142 //! \brief Returns the y or pitch value
143 inline XsReal y() const { return m_y; }
144 //! \brief Returns the z or yaw value
145 inline XsReal z() const { return m_z; }
146
147 //! \brief Returns true if the values of this and \a other are within \a tolerance of each other
148 inline bool isEqual(const XsEuler& other, XsReal tolerance) const
149 {
150 return fabs(m_x - other.m_x) <= tolerance &&
151 fabs(m_y - other.m_y) <= tolerance &&
152 fabs(m_z - other.m_z) <= tolerance;
153 }
154
155 private:
156 #endif
157
158 union {
159 struct {
160 XsReal m_x; //!< Stores the x component of the euler triplet
161 XsReal m_y; //!< Stores the y component of the euler triplet
162 XsReal m_z; //!< Stores the z component of the euler triplet
163 };
164 struct {
165 XsReal m_roll; //!< Stores the roll component of the euler triplet
166 XsReal m_pitch; //!< Stores the pitch component of the euler triplet
167 XsReal m_yaw; //!< Stores the yaw component of the euler triplet
168 };
169 XsReal m_data[3]; //!< Stores the euler triplet in an array of three elements
170 };
171 };
172
173 typedef struct XsEuler XsEuler;
174
175 #endif