The open source OpenXR runtime

a/util, d/android: change cardboard distortion calculation

Co-Authored-By: Simon Zeni <simon.zeni@collabora.com>
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2412>

authored by

artdeell
Simon Zeni
and committed by
Marge Bot
3009f375 24494054

+27 -18
+19 -11
src/xrt/auxiliary/util/u_distortion.c
··· 15 15 #include "util/u_device.h" 16 16 #include "util/u_distortion.h" 17 17 18 + #include <assert.h> 18 19 19 20 void 20 21 u_distortion_cardboard_calculate(const struct u_cardboard_distortion_arguments *args, ··· 26 27 */ 27 28 28 29 uint32_t view_count = parts->view_count; 30 + 31 + // Cardboard always has two views 32 + assert(view_count == 2); 29 33 30 34 uint32_t w_pixels = args->screen.w_pixels / view_count; 31 35 uint32_t h_pixels = args->screen.h_pixels; ··· 61 65 values->distortion_k[2] = args->distortion_k[2]; 62 66 values->distortion_k[3] = args->distortion_k[3]; 63 67 values->distortion_k[4] = args->distortion_k[4]; 64 - values->screen.size.x = args->screen.w_meters; 65 - values->screen.size.y = args->screen.h_meters; 66 - values->screen.offset.x = 67 - (args->screen.w_meters + pow(-1, i + 1) * args->inter_lens_distance_meters) / view_count; 68 - values->screen.offset.y = args->lens_y_center_on_screen_meters; 69 - // clang-format on 70 68 71 - // Turn into tanangles 72 - values->screen.size.x /= args->screen_to_lens_distance_meters; 73 - values->screen.size.y /= args->screen_to_lens_distance_meters; 74 - values->screen.offset.x /= args->screen_to_lens_distance_meters; 75 - values->screen.offset.y /= args->screen_to_lens_distance_meters; 69 + // Divide by view count since each view takes a part of the screen on the X axis 70 + values->screen.size.x = args->screen.w_meters / args->screen_to_lens_distance_meters; 71 + values->screen.size.y = args->screen.h_meters / args->screen_to_lens_distance_meters; 72 + 73 + if (i == 0) { 74 + values->screen.offset.x = ((args->screen.w_meters - args->inter_lens_distance_meters) / 2) / 75 + args->screen_to_lens_distance_meters; 76 + } else if (i == 1) { 77 + values->screen.offset.x = ((args->screen.w_meters + args->inter_lens_distance_meters) / 2) / 78 + args->screen_to_lens_distance_meters; 79 + } 80 + 81 + // Cardboard vertical alignment bottom 82 + values->screen.offset.y = 83 + (args->tray_to_lens_distance_meters - 0.003f) / args->screen_to_lens_distance_meters; 76 84 77 85 // Tanangle to texture coordinates 78 86 values->texture.size.x = tanf(-args->fov.angle_left) + tanf(args->fov.angle_right);
+5 -3
src/xrt/auxiliary/util/u_distortion.h
··· 43 43 //! Distances between the lenses in meters. 44 44 float inter_lens_distance_meters; 45 45 46 - //! Where on the y axis the center of the lens is on the screen. 47 - float lens_y_center_on_screen_meters; 48 - 49 46 /*! 50 47 * The distance to the lens from the screen, used to calculate calculate 51 48 * tanangle of various distances on the screen. 52 49 */ 53 50 float screen_to_lens_distance_meters; 51 + 52 + /*! 53 + * The distance from the tray (the bottom of the screen) to the lens center on the Y axis. 54 + */ 55 + float tray_to_lens_distance_meters; 54 56 55 57 //! Fov values that the cardboard configuration has given us. 56 58 struct xrt_fov fov;
+3 -4
src/xrt/drivers/android/android_sensors.c
··· 263 263 264 264 const uint32_t w_pixels = metrics.width_pixels; 265 265 const uint32_t h_pixels = metrics.height_pixels; 266 - const uint32_t ppi = metrics.density_dpi; 267 266 268 267 const float angle = 45 * M_PI / 180.0; // 0.698132; // 40Deg in rads 269 - const float w_meters = ((float)w_pixels / (float)ppi) * 0.0254f; 270 - const float h_meters = ((float)h_pixels / (float)ppi) * 0.0254f; 268 + const float w_meters = ((float)w_pixels / (float)metrics.xdpi) * 0.0254f; 269 + const float h_meters = ((float)h_pixels / (float)metrics.ydpi) * 0.0254f; 271 270 272 271 struct u_cardboard_distortion_arguments args = { 273 272 .distortion_k = {0.441f, 0.156f, 0.f, 0.f, 0.f}, ··· 279 278 .h_meters = h_meters, 280 279 }, 281 280 .inter_lens_distance_meters = 0.06f, 282 - .lens_y_center_on_screen_meters = h_meters / 2.0f, 283 281 .screen_to_lens_distance_meters = 0.042f, 282 + .tray_to_lens_distance_meters = 0.035f, 284 283 .fov = 285 284 { 286 285 .angle_left = -angle,