OSVR-Core
QuaternionC.h
Go to the documentation of this file.
1 
13 /*
14 // Copyright 2014 Sensics, Inc.
15 //
16 // Licensed under the Apache License, Version 2.0 (the "License");
17 // you may not use this file except in compliance with the License.
18 // You may obtain a copy of the License at
19 //
20 // http://www.apache.org/licenses/LICENSE-2.0
21 //
22 // Unless required by applicable law or agreed to in writing, software
23 // distributed under the License is distributed on an "AS IS" BASIS,
24 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 // See the License for the specific language governing permissions and
26 // limitations under the License.
27 */
28 
29 #ifndef INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66
30 #define INCLUDED_QuaternionC_h_GUID_1470A5FE_8209_41A6_C19E_46077FDF9C66
31 
32 /* Internal Includes */
33 #include <osvr/Util/APIBaseC.h>
34 
35 /* Library/third-party includes */
36 /* none */
37 
38 /* Standard includes */
39 /* none */
40 
41 OSVR_EXTERN_C_BEGIN
42 
49 typedef struct OSVR_Quaternion {
51  double data[4];
53 
54 #define OSVR_QUAT_MEMBER(COMPONENT, INDEX) \
55  \
56  OSVR_INLINE double osvrQuatGet##COMPONENT(OSVR_Quaternion const *q) { \
57  return q->data[INDEX]; \
58  } \
59  \
60  OSVR_INLINE void osvrQuatSet##COMPONENT(OSVR_Quaternion *q, double val) { \
61  q->data[INDEX] = val; \
62  }
63 
64 OSVR_QUAT_MEMBER(W, 0)
65 OSVR_QUAT_MEMBER(X, 1)
66 OSVR_QUAT_MEMBER(Y, 2)
67 OSVR_QUAT_MEMBER(Z, 3)
68 
69 #undef OSVR_QUAT_MEMBER
70 
72 OSVR_INLINE void osvrQuatSetIdentity(OSVR_Quaternion *q) {
73  osvrQuatSetW(q, 1);
74  osvrQuatSetX(q, 0);
75  osvrQuatSetY(q, 0);
76  osvrQuatSetZ(q, 0);
77 }
78 
81 OSVR_EXTERN_C_END
82 
83 #ifdef __cplusplus
84 template <typename StreamType>
85 inline StreamType &operator<<(StreamType &os, OSVR_Quaternion const &quat) {
86  os << "(" << osvrQuatGetW(&quat) << ", (" << osvrQuatGetX(&quat) << ", "
87  << osvrQuatGetY(&quat) << ", " << osvrQuatGetZ(&quat) << "))";
88  return os;
89 }
90 #endif
91 
92 #endif
double data[4]
Internal data - direct access not recommended.
Definition: QuaternionC.h:51
A structure defining a quaternion, often a unit quaternion representing 3D rotation.
Definition: QuaternionC.h:49
Header providing basic C macros for defining API headers.
OSVR_INLINE void osvrQuatSetIdentity(OSVR_Quaternion *q)
Set a quaternion to the identity rotation.
Definition: QuaternionC.h:72
struct OSVR_Quaternion OSVR_Quaternion
A structure defining a quaternion, often a unit quaternion representing 3D rotation.