VectorNav C Library
vector.h
1 #ifndef VN_VECTOR_H_INCLUDED
2 #define VN_VECTOR_H_INCLUDED
3 
4 #include "vn/util/compiler.h"
5 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
14 typedef union
15 {
16  float c[3];
18  /* Check if the compiler supports anonymous unions. */
19  #if defined(__STDC_VERSION___) && (__STDC_VERSION__ >= 201112L) && defined(__GNUC__)
20 
21  struct
22  {
23  float x;
24  float y;
25  float z;
26  };
27 
28  struct
29  {
30  float c0;
31  float c1;
32  float c2;
33  };
34 
35  #endif
36 
37 } vec3f;
38 
41 typedef union
42 {
43  double c[3];
45  /* Check if the compiler supports anonymous unions. */
46  #if defined(__STDC_VERSION___) && (__STDC_VERSION__ >= 201112L) && defined(__GNUC__)
47 
48  struct
49  {
50  double x;
51  double y;
52  double z;
53  };
54 
55  struct
56  {
57  double c0;
58  double c1;
59  double c2;
60  };
61 
62  #endif
63 
64 } vec3d;
65 
68 typedef union
69 {
70  float c[4];
72  /* Check if the compiler supports anonymous unions. */
73  #if (defined(__STDC_VERSION___) && (__STDC_VERSION__ >= 201112L)) && defined(__GNUC__)
74 
75  struct
76  {
77  float x;
78  float y;
79  float z;
80  float w;
81  };
82 
83  struct
84  {
85  float c0;
86  float c1;
87  float c2;
88  float c3;
89  };
90 
91  #endif
92 
93 } vec4f;
94 
99 void vn_v3_init_fa(vec3f* v, const float* fa);
100 
106 vec3d create_v3d(double x, double y, double z);
107 
113 vec3f add_v3f_v3f(vec3f lhs, vec3f rhs);
114 
120 vec3d add_v3d_v3d(vec3d lhs, vec3d rhs);
121 
127 vec4f add_v4f_v4f(vec4f lhs, vec4f rhs);
128 
134 vec3f sub_v3f_v3f(vec3f lhs, vec3f rhs);
135 
141 vec3d sub_v3d_v3d(vec3d lhs, vec3d rhs);
142 
148 vec4f sub_v4f_v4f(vec4f lhs, vec4f rhs);
149 
154 void str_vec3f(char* out, vec3f v);
155 
160 void str_vec3d(char* out, vec3d v);
161 
166 void str_vec4f(char* out, vec4f v);
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif
Represents a 4 component vector with an underlying data type of float.
Definition: vector.h:68
Represents a 3 component vector with an underlying data type of double.
Definition: vector.h:41
Various vector types and operations.
Definition: vector.h:14