The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/ns: possibly fix mesh calculation

also fix flipped tracking tracking

+32 -19
+32 -19
src/xrt/drivers/north_star/ns_hmd.c
··· 305 305 float v, 306 306 struct xrt_uv_triplet *result) 307 307 { 308 + u = 1.0 - u; // Not sure why these are necessary: somewhat concerning. 309 + v = 1.0 - v; // They make it work though, so hey. 310 + 308 311 struct ns_hmd *ns = ns_hmd(xdev); 309 312 310 - float x = 0.0f; 311 - float y = 0.0f; 312 - 313 - u = 1.0 - u; 314 - v = 1.0 - v; 315 - 316 - float L = ns->eye_configs_v2[view].fov.angle_left; 317 - float R = ns->eye_configs_v2[view].fov.angle_right; 318 - float T = ns->eye_configs_v2[view].fov.angle_up; 319 - float B = ns->eye_configs_v2[view].fov.angle_down; 320 - 321 313 float x_ray = 322 314 ns_v2_polyval2d(u, v, ns->eye_configs_v2[view].x_coefficients); 323 315 float y_ray = 324 316 ns_v2_polyval2d(u, v, ns->eye_configs_v2[view].y_coefficients); 325 317 326 - x = (x_ray + L) / (L - R); 327 - y = (y_ray + T) / (T - B); 328 318 319 + float left_ray_bound = tan(ns->eye_configs_v2[view].fov.angle_left); 320 + float right_ray_bound = tan(ns->eye_configs_v2[view].fov.angle_right); 321 + float up_ray_bound = tan(ns->eye_configs_v2[view].fov.angle_up); 322 + float down_ray_bound = tan(ns->eye_configs_v2[view].fov.angle_down); 329 323 330 - result->r.x = x; 331 - result->r.y = y; 332 - result->g.x = x; 333 - result->g.y = y; 334 - result->b.x = x; 335 - result->b.y = y; 324 + 325 + 326 + // Both of these are very concise implementations of map() in Arduino. 327 + // https://www.arduino.cc/reference/en/language/functions/math/map/ 328 + // In other words, a one-axis linear transformation. 329 + // I wish I was better at linear algebra so I had could describe this 330 + // better 331 + 332 + // map(x_ray, left_ray_bound, right_ray_bound, 0, 1) 333 + float u_eye = 334 + (x_ray + right_ray_bound) / (right_ray_bound - left_ray_bound); 335 + 336 + // map(y_ray, down_ray_bound, up_ray_bound, 0, 1) 337 + float v_eye = (y_ray + up_ray_bound) / (up_ray_bound - down_ray_bound); 338 + 339 + 340 + // boilerplate, put the UV coordinates in all the RGB slots 341 + result->r.x = u_eye; 342 + result->r.y = v_eye; 343 + result->g.x = u_eye; 344 + result->g.y = v_eye; 345 + result->b.x = u_eye; 346 + result->b.y = v_eye; 347 + 336 348 return true; 337 349 } 338 350 ··· 557 569 ns->base.hmd->distortion.preferred = 558 570 XRT_DISTORTION_MODEL_COMPUTE; 559 571 ns->base.compute_distortion = ns_v2_mesh_calc; 572 + 560 573 } else { 561 574 // V1 562 575 ns->base.get_view_pose = ns_hmd_get_view_pose;