The open source OpenXR runtime

d/android: Enable cardboard distortion.

authored by

Lubosz Sarnecki and committed by
Ryan Pavlik
ae1d4e95 f4113ef1

+51 -15
+48 -15
src/xrt/drivers/android/android_sensors.c
··· 15 15 #include "util/u_debug.h" 16 16 #include "util/u_device.h" 17 17 #include "util/u_var.h" 18 + #include "util/u_distortion_mesh.h" 18 19 19 20 // 60 events per second (in us). 20 21 #define POLL_RATE_USEC (1000L / 60) * 1000 ··· 202 203 * 203 204 */ 204 205 206 + static bool 207 + android_device_compute_distortion(struct xrt_device *xdev, 208 + int view, 209 + float u, 210 + float v, 211 + struct xrt_uv_triplet *result) 212 + { 213 + struct android_device *d = android_device(xdev); 214 + return u_compute_distortion_cardboard(&d->cardboard.values[view], u, v, 215 + result); 216 + } 217 + 218 + 205 219 struct android_device * 206 220 android_device_create() 207 221 { ··· 215 229 d->base.update_inputs = android_device_update_inputs; 216 230 d->base.get_tracked_pose = android_device_get_tracked_pose; 217 231 d->base.get_view_pose = android_device_get_view_pose; 232 + d->base.compute_distortion = android_device_compute_distortion; 218 233 d->base.inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; 219 234 d->base.device_type = XRT_DEVICE_TYPE_HMD; 220 235 ··· 230 245 return NULL; 231 246 } 232 247 233 - // Setup info. 234 - struct u_device_simple_info info; 235 - info.display.w_pixels = 1280; 236 - info.display.h_pixels = 720; 237 - info.display.w_meters = 0.13f; 238 - info.display.h_meters = 0.07f; 239 - info.lens_horizontal_separation_meters = 0.13f / 2.0f; 240 - info.lens_vertical_position_meters = 0.07f / 2.0f; 241 - info.views[0].fov = 85.0f * (M_PI / 180.0f); 242 - info.views[1].fov = 85.0f * (M_PI / 180.0f); 248 + const uint32_t w_pixels = 2960; 249 + const uint32_t h_pixels = 1440; 250 + const uint32_t ppi = 572; 243 251 244 - if (!u_device_setup_split_side_by_side(&d->base, &info)) { 245 - ANDROID_ERROR(d, "Failed to setup basic device info"); 246 - android_device_destroy(&d->base); 247 - return NULL; 248 - } 252 + const float angle = 45 * M_PI / 180.0; // 0.698132; // 40Deg in rads 253 + const float w_meters = ((float)w_pixels / (float)ppi) * 0.0254f; 254 + const float h_meters = ((float)h_pixels / (float)ppi) * 0.0254f; 255 + 256 + struct u_cardboard_distortion_arguments args = { 257 + .distortion_k = {0.441f, 0.156f, 0.f, 0.f, 0.f}, 258 + .screen = 259 + { 260 + .w_pixels = w_pixels, 261 + .h_pixels = h_pixels, 262 + .w_meters = w_meters, 263 + .h_meters = h_meters, 264 + }, 265 + .inter_lens_distance_meters = 0.06f, 266 + .lens_y_center_on_screen_meters = h_meters / 2.0f, 267 + .screen_to_lens_distance_meters = 0.042f, 268 + .fov = 269 + { 270 + .angle_left = -angle, 271 + .angle_right = angle, 272 + .angle_up = angle, 273 + .angle_down = -angle, 274 + }, 275 + }; 276 + 277 + u_distortion_cardboard_calculate(&args, d->base.hmd, &d->cardboard); 278 + 249 279 250 280 u_var_add_root(d, "Android phone", true); 251 281 u_var_add_ro_vec3_f32(d, &d->fusion.last.accel, "last.accel"); ··· 253 283 254 284 d->base.orientation_tracking_supported = true; 255 285 d->base.position_tracking_supported = false; 286 + 287 + // Distortion information. 288 + u_distortion_mesh_fill_in_compute(&d->base); 256 289 257 290 ANDROID_DEBUG(d, "Created device!"); 258 291
+3
src/xrt/drivers/android/android_sensors.h
··· 20 20 #include "os/os_threading.h" 21 21 22 22 #include "util/u_logging.h" 23 + #include "util/u_distortion.h" 23 24 24 25 #ifdef __cplusplus 25 26 extern "C" { ··· 37 38 const ASensor *accelerometer; 38 39 const ASensor *gyroscope; 39 40 ASensorEventQueue *event_queue; 41 + struct u_cardboard_distortion cardboard; 42 + 40 43 41 44 struct 42 45 {