OSVR-Core
Vec2C.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_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
30 #define INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
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_Vec2 {
50  double data[2];
51 } OSVR_Vec2;
52 
53 #define OSVR_VEC_MEMBER(COMPONENT, INDEX) \
54  \
55  OSVR_INLINE double osvrVec2Get##COMPONENT(OSVR_Vec2 const *v) { \
56  return v->data[INDEX]; \
57  } \
58  \
59  OSVR_INLINE void osvrVec2Set##COMPONENT(OSVR_Vec2 *v, double val) { \
60  v->data[INDEX] = val; \
61  }
62 
63 OSVR_VEC_MEMBER(X, 0)
64 OSVR_VEC_MEMBER(Y, 1)
65 
66 #undef OSVR_VEC_MEMBER
67 
69 OSVR_INLINE void osvrVec2Zero(OSVR_Vec2 *v) {
70  osvrVec2SetX(v, 0);
71  osvrVec2SetY(v, 0);
72 }
73 
76 OSVR_EXTERN_C_END
77 
78 #ifdef __cplusplus
79 template <typename StreamType>
80 inline StreamType &operator<<(StreamType &os, OSVR_Vec2 const &vec) {
81  os << "(" << vec.data[0] << ", " << vec.data[1] << ")";
82  return os;
83 }
84 #endif
85 
86 #endif // INCLUDED_Vec2C_h_GUID_F9715DE4_2649_4182_0F4C_D62121235D5F
struct OSVR_Vec2 OSVR_Vec2
A structure defining a 2D vector, which represents position.
A structure defining a 2D vector, which represents position.
Definition: Vec2C.h:48
double data[2]
Internal array data.
Definition: Vec2C.h:50
Header providing basic C macros for defining API headers.
OSVR_INLINE void osvrVec2Zero(OSVR_Vec2 *v)
Set a Vec2 to the zero vector.
Definition: Vec2C.h:69