OSSIA
Open Scenario System for Interactive Application
position.hpp
1 #pragma once
2 #include <ossia/network/dataspace/dataspace_base.hpp>
3 #include <ossia/network/domain/domain.hpp>
4 namespace ossia
5 {
6 struct cartesian_3d_u;
7 struct position_u;
8 template <typename Impl>
9 struct position_unit
10 {
11  using is_unit = std::true_type;
12  using is_multidimensional = std::true_type;
13  using dataspace_type = position_u;
14  using neutral_unit = cartesian_3d_u;
15  using concrete_type = Impl;
16 };
17 
18 struct OSSIA_EXPORT cartesian_3d_u : public position_unit<cartesian_3d_u>
19 {
20  static constexpr auto text()
21  {
22  constexpr_return(ossia::make_string_array("cart3D", "xyz"));
23  }
24  static constexpr auto array_parameters()
25  {
26  constexpr_return(ossia::make_string_view("xyz"));
27  }
28  static constexpr auto units()
29  {
30  constexpr_return(ossia::make_string_array("distance.m", "distance.m", "distance.m"));
31  }
32  using value_type = vec3f;
33  static constexpr strong_value<neutral_unit>
34  to_neutral(strong_value<concrete_type> self)
35  {
36  return self;
37  }
38 
39  static constexpr value_type from_neutral(strong_value<neutral_unit> self)
40  {
41  return self.dataspace_value;
42  }
43 
44  static ossia::vecf_domain<3> domain()
45  {
46  return vecf_domain<3>{
47  ossia::make_vec(-1.f, -1.f, -1.f), ossia::make_vec(1.f, 1.f, 1.f)};
48  }
49 
50  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
51 };
52 
53 struct OSSIA_EXPORT cartesian_2d_u : public position_unit<cartesian_2d_u>
54 {
55  static constexpr auto text()
56  {
57  constexpr_return(ossia::make_string_array("cart2D", "xy"));
58  }
59  static constexpr auto array_parameters()
60  {
61  constexpr_return(ossia::make_string_view("xy"));
62  }
63  static constexpr auto units()
64  {
65  constexpr_return(ossia::make_string_array("distance.m", "distance.m"));
66  }
67  using value_type = vec2f;
68  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
69  {
70  return {self.dataspace_value[0], self.dataspace_value[1], 0.f};
71  }
72 
73  static value_type from_neutral(strong_value<neutral_unit> self)
74  {
75  return {self.dataspace_value[0], self.dataspace_value[1]};
76  }
77 
78  static ossia::vecf_domain<2> domain()
79  {
80  return vecf_domain{ossia::make_vec(-1.f, -1.f), ossia::make_vec(1.f, 1.f)};
81  }
82 
83  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
84 };
85 
86 struct OSSIA_EXPORT spherical_u : public position_unit<spherical_u>
87 {
88  static constexpr auto text()
89  {
90  constexpr_return(ossia::make_string_array("spherical", "rtp"));
91  }
92  static constexpr auto array_parameters()
93  {
94  constexpr_return(ossia::make_string_view("rtp"));
95  }
96  static constexpr auto units()
97  {
98  constexpr_return(
99  ossia::make_string_array("distance.m", "angle.radiant", "angle.radiant"));
100  }
101  using value_type = vec3f;
102  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
103 
104  static value_type from_neutral(strong_value<neutral_unit> self);
105 
106  static ossia::vecf_domain<3> domain()
107  {
108  return vecf_domain<3>{
109  ossia::make_vec(0.f, -pi, -half_pi), ossia::make_vec(1.f, pi, half_pi)};
110  }
111 
112  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
113 };
114 
115 struct OSSIA_EXPORT polar_u : public position_unit<polar_u>
116 {
117  static constexpr auto text()
118  {
119  constexpr_return(ossia::make_string_array("polar", "rp"));
120  }
121  static constexpr auto array_parameters()
122  {
123  constexpr_return(ossia::make_string_view("rp"));
124  }
125  static constexpr auto units()
126  {
127  constexpr_return(ossia::make_string_array("distance.m", "angle.radiant"));
128  }
129  using value_type = vec2f;
130  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
131  {
132  const auto r = self.dataspace_value[0];
133  const auto t = self.dataspace_value[1];
134 
135  return {(float)(std::cos(t) * r), (float)(std::sin(t) * r)};
136  }
137 
138  static value_type from_neutral(strong_value<neutral_unit> self)
139  {
140  const auto x = self.dataspace_value[0];
141  const auto y = self.dataspace_value[1];
142 
143  return {(float)(ossia::norm(x, y)), (float)(std::atan2(y, x))};
144  }
145 
146  static ossia::vecf_domain<2> domain()
147  {
148  return vecf_domain<2>{ossia::make_vec(0.f, -pi), ossia::make_vec(1.f, pi)};
149  }
150 
151  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
152 };
153 
154 struct OSSIA_EXPORT aed_u : public position_unit<aed_u>
155 {
156  static constexpr auto text()
157  {
158  constexpr_return(ossia::make_string_array("AED", "aed"));
159  }
160  static constexpr auto array_parameters()
161  {
162  constexpr_return(ossia::make_string_view("aed"));
163  }
164  static constexpr auto units()
165  {
166  constexpr_return(
167  ossia::make_string_array("angle.degree", "angle.degree", "distance.m"));
168  }
169  using value_type = vec3f;
170  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
171 
172  static value_type from_neutral(strong_value<neutral_unit> self);
173 
174  static ossia::vecf_domain<3> domain()
175  {
176  return vecf_domain<3>{
177  ossia::make_vec(-180.f, -180.f, 0.f), ossia::make_vec(180.f, 180.f, 1.f)};
178  }
179 
180  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
181 };
182 
183 struct OSSIA_EXPORT ad_u : public position_unit<ad_u>
184 {
185  static constexpr auto text()
186  {
187  constexpr_return(ossia::make_string_array("AD", "ad"));
188  }
189  static constexpr auto array_parameters()
190  {
191  constexpr_return(ossia::make_string_view("ad"));
192  }
193  static constexpr auto units()
194  {
195  constexpr_return(ossia::make_string_array("angle.degree", "distance.m"));
196  }
197  using value_type = vec2f;
198  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
199  {
200  const auto a = self.dataspace_value[0] * deg_to_rad - half_pi;
201  const auto d = self.dataspace_value[1];
202 
203  return {(float)(std::sin(-a) * d), (float)(std::cos(-a) * d), 0.f};
204  }
205 
206  static value_type from_neutral(strong_value<neutral_unit> self)
207  {
208  const auto x = self.dataspace_value[0];
209  const auto y = self.dataspace_value[1];
210 
211  return {
212  -(float)(std::atan2(y, x) + half_pi * rad_to_deg), (float)(ossia::norm(x, y))};
213  }
214 
215  static ossia::vecf_domain<2> domain()
216  {
217  return vecf_domain<2>{ossia::make_vec(-180.f, 0.f), ossia::make_vec(180.f, 0.f)};
218  }
219 
220  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
221 };
222 
223 struct OSSIA_EXPORT opengl_u : public position_unit<opengl_u>
224 {
225  static constexpr auto text() { constexpr_return(ossia::make_string_array("openGL")); }
226  static constexpr auto array_parameters()
227  {
228  constexpr_return(ossia::make_string_view("xyz"));
229  }
230  static constexpr auto units()
231  {
232  constexpr_return(ossia::make_string_array("distance.m", "distance.m", "distance.m"));
233  }
234  using value_type = vec3f;
235  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self)
236  {
237  return {self.dataspace_value[0], -self.dataspace_value[2], self.dataspace_value[1]};
238  }
239 
240  static value_type from_neutral(strong_value<neutral_unit> self)
241  {
242  return {self.dataspace_value[0], self.dataspace_value[2], -self.dataspace_value[1]};
243  }
244 
245  static ossia::vecf_domain<3> domain()
246  {
247  return vecf_domain{
248  ossia::make_vec(-1.f, -1.f, -1.f), ossia::make_vec(1.f, 1.f, 1.f)};
249  }
250 
251  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
252 };
253 
254 struct OSSIA_EXPORT cylindrical_u : public position_unit<cylindrical_u>
255 {
256  static constexpr auto text()
257  {
258  constexpr_return(ossia::make_string_array("cylindrical", "rtz"));
259  }
260  static constexpr auto array_parameters()
261  {
262  constexpr_return(ossia::make_string_view("rtz"));
263  }
264  static constexpr auto units()
265  {
266  constexpr_return(
267  ossia::make_string_array("distance.m", "angle.degree", "distance.m"));
268  }
269  using value_type = vec3f;
270  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
271 
272  static value_type from_neutral(strong_value<neutral_unit> self);
273 
274  static ossia::vecf_domain<3> domain()
275  {
276  return vecf_domain<3>{
277  ossia::make_vec(0.f, -180.f, 0.f), ossia::make_vec(1.f, 180.f, 1.f)};
278  }
279  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
280 };
281 
282 struct OSSIA_EXPORT azd_u : public position_unit<azd_u>
283 {
284  static constexpr auto text()
285  {
286  constexpr_return(ossia::make_string_array("AZD", "azd"));
287  }
288  static constexpr auto array_parameters()
289  {
290  constexpr_return(ossia::make_string_view("azd"));
291  }
292  static constexpr auto units()
293  {
294  constexpr_return(
295  ossia::make_string_array("angle.degree", "distance.m", "distance.m"));
296  }
297  using value_type = vec3f;
298  static strong_value<neutral_unit> to_neutral(strong_value<concrete_type> self);
299 
300  static value_type from_neutral(strong_value<neutral_unit> self);
301 
302  static ossia::vecf_domain<3> domain()
303  {
304  return vecf_domain<3>{
305  ossia::make_vec(-180.f, -1.f, 0.f), ossia::make_vec(180.f, 1.f, 1.f)};
306  }
307  static constexpr auto bounding() { return ossia::bounding_mode::FREE; }
308 };
309 }
Definition: git_info.h:7