OSVR-Core
Vec3C.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_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE
30 #define INCLUDED_Vec3C_h_GUID_BF4E98ED_74CF_4785_DB61_109A00BA74DE
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 
48 typedef struct OSVR_Vec3 {
50  double data[3];
51 } OSVR_Vec3;
52 
53 #define OSVR_VEC_MEMBER(COMPONENT, INDEX) \
54  \
55  OSVR_INLINE double osvrVec3Get##COMPONENT(OSVR_Vec3 const *v) { \
56  return v->data[INDEX]; \
57  } \
58  \
59  OSVR_INLINE void osvrVec3Set##COMPONENT(OSVR_Vec3 *v, double val) { \
60  v->data[INDEX] = val; \
61  }
62 
63 OSVR_VEC_MEMBER(X, 0)
64 OSVR_VEC_MEMBER(Y, 1)
65 OSVR_VEC_MEMBER(Z, 2)
66 
67 #undef OSVR_VEC_MEMBER
68 
70 OSVR_INLINE void osvrVec3Zero(OSVR_Vec3 *v) {
71  osvrVec3SetX(v, 0);
72  osvrVec3SetY(v, 0);
73  osvrVec3SetZ(v, 0);
74 }
75 
78 OSVR_EXTERN_C_END
79 
80 #ifdef __cplusplus
81 template <typename StreamType>
82 inline StreamType &operator<<(StreamType &os, OSVR_Vec3 const &vec) {
83  os << "(" << vec.data[0] << ", " << vec.data[1] << ", " << vec.data[2]
84  << ")";
85  return os;
86 }
87 #endif
88 
89 #endif
A structure defining a 3D vector, often a position/translation.
Definition: Vec3C.h:48
OSVR_INLINE void osvrVec3Zero(OSVR_Vec3 *v)
Set a Vec3 to the zero vector.
Definition: Vec3C.h:70
double data[3]
Internal array data.
Definition: Vec3C.h:50
struct OSVR_Vec3 OSVR_Vec3
A structure defining a 3D vector, often a position/translation.
Header providing basic C macros for defining API headers.