OSVR-Core
QuatlibInteropC.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_QuatlibInteropC_h_GUID_85D92019_F0CC_419C_5F6D_F5A3134AA5D4
30 #define INCLUDED_QuatlibInteropC_h_GUID_85D92019_F0CC_419C_5F6D_F5A3134AA5D4
31 
32 /* Internal Includes */
33 #include <osvr/Util/APIBaseC.h>
34 #include <osvr/Util/Pose3C.h>
35 
36 /* Library/third-party includes */
37 #include <quat.h>
38 
39 /* Standard includes */
40 #include <string.h>
41 
42 OSVR_EXTERN_C_BEGIN
43 
47 OSVR_INLINE void osvrQuatToQuatlib(q_type dest, OSVR_Quaternion const *src) {
48  dest[Q_W] = osvrQuatGetW(src);
49  dest[Q_X] = osvrQuatGetX(src);
50  dest[Q_Y] = osvrQuatGetY(src);
51  dest[Q_Z] = osvrQuatGetZ(src);
52 }
53 
54 OSVR_INLINE void osvrQuatFromQuatlib(OSVR_Quaternion *dest, q_type const src) {
55  osvrQuatSetW(dest, src[Q_W]);
56  osvrQuatSetX(dest, src[Q_X]);
57  osvrQuatSetY(dest, src[Q_Y]);
58  osvrQuatSetZ(dest, src[Q_Z]);
59 }
60 
61 OSVR_INLINE void osvrVec3ToQuatlib(q_vec_type dest, OSVR_Vec3 const *src) {
62  memcpy((void *)(dest), (void const *)(src->data), sizeof(double) * 3);
63 }
64 
65 OSVR_INLINE void osvrVec3FromQuatlib(OSVR_Vec3 *dest, q_vec_type const src) {
66  memcpy((void *)(dest->data), (void const *)(src), sizeof(double) * 3);
67 }
68 
69 OSVR_INLINE void osvrPose3ToQuatlib(q_xyz_quat_type *dest,
70  OSVR_Pose3 const *src) {
71  osvrVec3ToQuatlib(dest->xyz, &(src->translation));
72  osvrQuatToQuatlib(dest->quat, &(src->rotation));
73 }
74 
75 OSVR_INLINE void osvrPose3FromQuatlib(OSVR_Pose3 *dest,
76  q_xyz_quat_type const *src) {
77  osvrVec3FromQuatlib(&(dest->translation), src->xyz);
78  osvrQuatFromQuatlib(&(dest->rotation), src->quat);
79 }
80 
83 OSVR_EXTERN_C_END
84 #endif
A structure defining a 3D vector, often a position/translation.
Definition: Vec3C.h:48
OSVR_Quaternion rotation
Orientation as a unit quaternion.
Definition: Pose3C.h:58
A structure defining a quaternion, often a unit quaternion representing 3D rotation.
Definition: QuaternionC.h:49
double data[3]
Internal array data.
Definition: Vec3C.h:50
Header providing basic C macros for defining API headers.
A structure defining a 3D (6DOF) rigid body pose: translation and rotation.
Definition: Pose3C.h:54
Header.
OSVR_Vec3 translation
Position vector.
Definition: Pose3C.h:56