Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/mobile_vr/mobile_vr_interface.cpp
10277 views
1
/**************************************************************************/
2
/* mobile_vr_interface.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "mobile_vr_interface.h"
32
33
#include "core/input/input.h"
34
#include "core/os/os.h"
35
#include "servers/display_server.h"
36
#include "servers/rendering/renderer_compositor.h"
37
38
StringName MobileVRInterface::get_name() const {
39
return "Native mobile";
40
}
41
42
uint32_t MobileVRInterface::get_capabilities() const {
43
return XRInterface::XR_STEREO;
44
}
45
46
Vector3 MobileVRInterface::scale_magneto(const Vector3 &p_magnetometer) {
47
// Our magnetometer doesn't give us nice clean data.
48
// Well it may on macOS because we're getting a calibrated value in the current implementation but Android we're getting raw data.
49
// This is a fairly simple adjustment we can do to correct for the magnetometer data being elliptical
50
51
Vector3 mag_raw = p_magnetometer;
52
Vector3 mag_scaled = p_magnetometer;
53
54
// update our variables every x frames
55
if (mag_count > 20) {
56
mag_current_min = mag_next_min;
57
mag_current_max = mag_next_max;
58
mag_count = 0;
59
} else {
60
mag_count++;
61
};
62
63
// adjust our min and max
64
if (mag_raw.x > mag_next_max.x) {
65
mag_next_max.x = mag_raw.x;
66
}
67
if (mag_raw.y > mag_next_max.y) {
68
mag_next_max.y = mag_raw.y;
69
}
70
if (mag_raw.z > mag_next_max.z) {
71
mag_next_max.z = mag_raw.z;
72
}
73
74
if (mag_raw.x < mag_next_min.x) {
75
mag_next_min.x = mag_raw.x;
76
}
77
if (mag_raw.y < mag_next_min.y) {
78
mag_next_min.y = mag_raw.y;
79
}
80
if (mag_raw.z < mag_next_min.z) {
81
mag_next_min.z = mag_raw.z;
82
}
83
84
// scale our x, y and z
85
if (!(mag_current_max.x - mag_current_min.x)) {
86
mag_raw.x -= (mag_current_min.x + mag_current_max.x) / 2.0;
87
mag_scaled.x = (mag_raw.x - mag_current_min.x) / ((mag_current_max.x - mag_current_min.x) * 2.0 - 1.0);
88
};
89
90
if (!(mag_current_max.y - mag_current_min.y)) {
91
mag_raw.y -= (mag_current_min.y + mag_current_max.y) / 2.0;
92
mag_scaled.y = (mag_raw.y - mag_current_min.y) / ((mag_current_max.y - mag_current_min.y) * 2.0 - 1.0);
93
};
94
95
if (!(mag_current_max.z - mag_current_min.z)) {
96
mag_raw.z -= (mag_current_min.z + mag_current_max.z) / 2.0;
97
mag_scaled.z = (mag_raw.z - mag_current_min.z) / ((mag_current_max.z - mag_current_min.z) * 2.0 - 1.0);
98
};
99
100
return mag_scaled;
101
}
102
103
Basis MobileVRInterface::combine_acc_mag(const Vector3 &p_grav, const Vector3 &p_magneto) {
104
// yup, stock standard cross product solution...
105
Vector3 up = -p_grav.normalized();
106
107
Vector3 magneto_east = up.cross(p_magneto.normalized()); // or is this west?, but should be horizon aligned now
108
magneto_east.normalize();
109
110
Vector3 magneto = up.cross(magneto_east); // and now we have a horizon aligned north
111
magneto.normalize();
112
113
// We use our gravity and magnetometer vectors to construct our matrix
114
Basis acc_mag_m3;
115
acc_mag_m3.rows[0] = -magneto_east;
116
acc_mag_m3.rows[1] = up;
117
acc_mag_m3.rows[2] = magneto;
118
119
return acc_mag_m3;
120
}
121
122
void MobileVRInterface::set_position_from_sensors() {
123
_THREAD_SAFE_METHOD_
124
125
// this is a helper function that attempts to adjust our transform using our 9dof sensors
126
// 9dof is a misleading marketing term coming from 3 accelerometer axis + 3 gyro axis + 3 magnetometer axis = 9 axis
127
// but in reality this only offers 3 dof (yaw, pitch, roll) orientation
128
129
Basis orientation = head_transform.basis;
130
131
uint64_t ticks = OS::get_singleton()->get_ticks_usec();
132
uint64_t ticks_elapsed = ticks - last_ticks;
133
float delta_time = (double)ticks_elapsed / 1000000.0;
134
135
// few things we need
136
Input *input = Input::get_singleton();
137
Vector3 down(0.0, -1.0, 0.0); // Down is Y negative
138
139
// make copies of our inputs
140
bool has_grav = false;
141
Vector3 acc = input->get_accelerometer();
142
Vector3 gyro = input->get_gyroscope();
143
Vector3 grav = input->get_gravity();
144
Vector3 magneto = scale_magneto(input->get_magnetometer()); // this may be overkill on iOS because we're already getting a calibrated magnetometer reading
145
146
if (sensor_first) {
147
sensor_first = false;
148
} else {
149
acc = scrub(acc, last_accerometer_data, 2, 0.2);
150
magneto = scrub(magneto, last_magnetometer_data, 3, 0.3);
151
};
152
153
last_accerometer_data = acc;
154
last_magnetometer_data = magneto;
155
156
if (grav.length() < 0.1) {
157
// not ideal but use our accelerometer, this will contain shaky user behavior
158
// maybe look into some math but I'm guessing that if this isn't available, it's because we lack the gyro sensor to actually work out
159
// what a stable gravity vector is
160
grav = acc;
161
if (grav.length() > 0.1) {
162
has_grav = true;
163
};
164
} else {
165
has_grav = true;
166
};
167
168
bool has_magneto = magneto.length() > 0.1;
169
if (gyro.length() > 0.1) {
170
/* this can return to 0.0 if the user doesn't move the phone, so once on, it's on */
171
has_gyro = true;
172
};
173
174
if (has_gyro) {
175
// start with applying our gyro (do NOT smooth our gyro!)
176
Basis rotate;
177
rotate.rotate(orientation.get_column(0), gyro.x * delta_time);
178
rotate.rotate(orientation.get_column(1), gyro.y * delta_time);
179
rotate.rotate(orientation.get_column(2), gyro.z * delta_time);
180
orientation = rotate * orientation;
181
182
tracking_state = XRInterface::XR_NORMAL_TRACKING;
183
tracking_confidence = XRPose::XR_TRACKING_CONFIDENCE_HIGH;
184
};
185
186
///@TODO improve this, the magnetometer is very fidgety sometimes flipping the axis for no apparent reason (probably a bug on my part)
187
// if you have a gyro + accelerometer that combo tends to be better than combining all three but without a gyro you need the magnetometer..
188
if (has_magneto && has_grav && !has_gyro) {
189
// convert to quaternions, easier to smooth those out
190
Quaternion transform_quat(orientation);
191
Quaternion acc_mag_quat(combine_acc_mag(grav, magneto));
192
transform_quat = transform_quat.slerp(acc_mag_quat, 0.1);
193
orientation = Basis(transform_quat);
194
195
tracking_state = XRInterface::XR_NORMAL_TRACKING;
196
tracking_confidence = XRPose::XR_TRACKING_CONFIDENCE_HIGH;
197
} else if (has_grav) {
198
// use gravity vector to make sure down is down...
199
// transform gravity into our world space
200
grav.normalize();
201
Vector3 grav_adj = orientation.xform(grav);
202
float dot = grav_adj.dot(down);
203
if ((dot > -1.0) && (dot < 1.0)) {
204
// axis around which we have this rotation
205
Vector3 axis = grav_adj.cross(down);
206
axis.normalize();
207
208
Basis drift_compensation(axis, std::acos(dot) * delta_time * 10);
209
orientation = drift_compensation * orientation;
210
};
211
};
212
213
// and copy to our head transform
214
head_transform.basis = orientation.orthonormalized();
215
216
last_ticks = ticks;
217
}
218
219
void MobileVRInterface::_bind_methods() {
220
ClassDB::bind_method(D_METHOD("set_eye_height", "eye_height"), &MobileVRInterface::set_eye_height);
221
ClassDB::bind_method(D_METHOD("get_eye_height"), &MobileVRInterface::get_eye_height);
222
223
ClassDB::bind_method(D_METHOD("set_iod", "iod"), &MobileVRInterface::set_iod);
224
ClassDB::bind_method(D_METHOD("get_iod"), &MobileVRInterface::get_iod);
225
226
ClassDB::bind_method(D_METHOD("set_display_width", "display_width"), &MobileVRInterface::set_display_width);
227
ClassDB::bind_method(D_METHOD("get_display_width"), &MobileVRInterface::get_display_width);
228
229
ClassDB::bind_method(D_METHOD("set_display_to_lens", "display_to_lens"), &MobileVRInterface::set_display_to_lens);
230
ClassDB::bind_method(D_METHOD("get_display_to_lens"), &MobileVRInterface::get_display_to_lens);
231
232
ClassDB::bind_method(D_METHOD("set_offset_rect", "offset_rect"), &MobileVRInterface::set_offset_rect);
233
ClassDB::bind_method(D_METHOD("get_offset_rect"), &MobileVRInterface::get_offset_rect);
234
235
ClassDB::bind_method(D_METHOD("set_oversample", "oversample"), &MobileVRInterface::set_oversample);
236
ClassDB::bind_method(D_METHOD("get_oversample"), &MobileVRInterface::get_oversample);
237
238
ClassDB::bind_method(D_METHOD("set_k1", "k"), &MobileVRInterface::set_k1);
239
ClassDB::bind_method(D_METHOD("get_k1"), &MobileVRInterface::get_k1);
240
241
ClassDB::bind_method(D_METHOD("set_k2", "k"), &MobileVRInterface::set_k2);
242
ClassDB::bind_method(D_METHOD("get_k2"), &MobileVRInterface::get_k2);
243
244
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "eye_height", PROPERTY_HINT_RANGE, "0.0,3.0,0.1"), "set_eye_height", "get_eye_height");
245
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "iod", PROPERTY_HINT_RANGE, "4.0,10.0,0.1"), "set_iod", "get_iod");
246
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_width", PROPERTY_HINT_RANGE, "5.0,25.0,0.1"), "set_display_width", "get_display_width");
247
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "display_to_lens", PROPERTY_HINT_RANGE, "5.0,25.0,0.1"), "set_display_to_lens", "get_display_to_lens");
248
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "offset_rect"), "set_offset_rect", "get_offset_rect");
249
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversample", PROPERTY_HINT_RANGE, "1.0,2.0,0.1"), "set_oversample", "get_oversample");
250
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "k1", PROPERTY_HINT_RANGE, "0.1,10.0,0.0001"), "set_k1", "get_k1");
251
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "k2", PROPERTY_HINT_RANGE, "0.1,10.0,0.0001"), "set_k2", "get_k2");
252
253
ClassDB::bind_method(D_METHOD("get_vrs_min_radius"), &MobileVRInterface::get_vrs_min_radius);
254
ClassDB::bind_method(D_METHOD("set_vrs_min_radius", "radius"), &MobileVRInterface::set_vrs_min_radius);
255
256
ClassDB::bind_method(D_METHOD("get_vrs_strength"), &MobileVRInterface::get_vrs_strength);
257
ClassDB::bind_method(D_METHOD("set_vrs_strength", "strength"), &MobileVRInterface::set_vrs_strength);
258
259
ADD_GROUP("Vulkan VRS", "vrs_");
260
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "vrs_min_radius", PROPERTY_HINT_RANGE, "1.0,100.0,1.0"), "set_vrs_min_radius", "get_vrs_min_radius");
261
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "vrs_strength", PROPERTY_HINT_RANGE, "0.1,10.0,0.1"), "set_vrs_strength", "get_vrs_strength");
262
}
263
264
void MobileVRInterface::set_eye_height(const double p_eye_height) {
265
eye_height = p_eye_height;
266
}
267
268
double MobileVRInterface::get_eye_height() const {
269
return eye_height;
270
}
271
272
void MobileVRInterface::set_offset_rect(const Rect2 &p_offset_rect) {
273
offset_rect = p_offset_rect;
274
}
275
276
Rect2 MobileVRInterface::get_offset_rect() const {
277
return offset_rect;
278
}
279
280
void MobileVRInterface::set_iod(const double p_iod) {
281
intraocular_dist = p_iod;
282
}
283
284
double MobileVRInterface::get_iod() const {
285
return intraocular_dist;
286
}
287
288
void MobileVRInterface::set_display_width(const double p_display_width) {
289
display_width = p_display_width;
290
}
291
292
double MobileVRInterface::get_display_width() const {
293
return display_width;
294
}
295
296
void MobileVRInterface::set_display_to_lens(const double p_display_to_lens) {
297
display_to_lens = p_display_to_lens;
298
}
299
300
double MobileVRInterface::get_display_to_lens() const {
301
return display_to_lens;
302
}
303
304
void MobileVRInterface::set_oversample(const double p_oversample) {
305
oversample = p_oversample;
306
}
307
308
double MobileVRInterface::get_oversample() const {
309
return oversample;
310
}
311
312
void MobileVRInterface::set_k1(const double p_k1) {
313
k1 = p_k1;
314
}
315
316
double MobileVRInterface::get_k1() const {
317
return k1;
318
}
319
320
void MobileVRInterface::set_k2(const double p_k2) {
321
k2 = p_k2;
322
}
323
324
double MobileVRInterface::get_k2() const {
325
return k2;
326
}
327
328
float MobileVRInterface::get_vrs_min_radius() const {
329
return xr_vrs.get_vrs_min_radius();
330
}
331
332
void MobileVRInterface::set_vrs_min_radius(float p_vrs_min_radius) {
333
xr_vrs.set_vrs_min_radius(p_vrs_min_radius);
334
}
335
336
float MobileVRInterface::get_vrs_strength() const {
337
return xr_vrs.get_vrs_strength();
338
}
339
340
void MobileVRInterface::set_vrs_strength(float p_vrs_strength) {
341
xr_vrs.set_vrs_strength(p_vrs_strength);
342
}
343
344
uint32_t MobileVRInterface::get_view_count() {
345
// needs stereo...
346
return 2;
347
}
348
349
XRInterface::TrackingStatus MobileVRInterface::get_tracking_status() const {
350
return tracking_state;
351
}
352
353
bool MobileVRInterface::is_initialized() const {
354
return (initialized);
355
}
356
357
bool MobileVRInterface::initialize() {
358
XRServer *xr_server = XRServer::get_singleton();
359
ERR_FAIL_NULL_V(xr_server, false);
360
361
if (!initialized) {
362
// reset our sensor data
363
mag_count = 0;
364
has_gyro = false;
365
sensor_first = true;
366
mag_next_min = Vector3(10000, 10000, 10000);
367
mag_next_max = Vector3(-10000, -10000, -10000);
368
mag_current_min = Vector3(0, 0, 0);
369
mag_current_max = Vector3(0, 0, 0);
370
head_transform.basis = Basis();
371
head_transform.origin = Vector3(0.0, eye_height, 0.0);
372
373
// we must create a tracker for our head
374
head.instantiate();
375
head->set_tracker_type(XRServer::TRACKER_HEAD);
376
head->set_tracker_name("head");
377
head->set_tracker_desc("Players head");
378
xr_server->add_tracker(head);
379
380
// make this our primary interface
381
xr_server->set_primary_interface(this);
382
383
last_ticks = OS::get_singleton()->get_ticks_usec();
384
385
initialized = true;
386
};
387
388
return true;
389
}
390
391
void MobileVRInterface::uninitialize() {
392
if (initialized) {
393
// do any cleanup here...
394
XRServer *xr_server = XRServer::get_singleton();
395
if (xr_server != nullptr) {
396
if (head.is_valid()) {
397
xr_server->remove_tracker(head);
398
399
head.unref();
400
}
401
402
if (xr_server->get_primary_interface() == this) {
403
// no longer our primary interface
404
xr_server->set_primary_interface(nullptr);
405
}
406
}
407
408
initialized = false;
409
};
410
}
411
412
Dictionary MobileVRInterface::get_system_info() {
413
Dictionary dict;
414
415
dict[SNAME("XRRuntimeName")] = String("Godot mobile VR interface");
416
dict[SNAME("XRRuntimeVersion")] = String("");
417
418
return dict;
419
}
420
421
bool MobileVRInterface::supports_play_area_mode(XRInterface::PlayAreaMode p_mode) {
422
// This interface has no positional tracking so fix this to 3DOF
423
return p_mode == XR_PLAY_AREA_3DOF;
424
}
425
426
XRInterface::PlayAreaMode MobileVRInterface::get_play_area_mode() const {
427
return XR_PLAY_AREA_3DOF;
428
}
429
430
bool MobileVRInterface::set_play_area_mode(XRInterface::PlayAreaMode p_mode) {
431
return p_mode == XR_PLAY_AREA_3DOF;
432
}
433
434
Size2 MobileVRInterface::get_render_target_size() {
435
_THREAD_SAFE_METHOD_
436
437
// we use half our window size
438
Size2 target_size = DisplayServer::get_singleton()->window_get_size();
439
440
target_size.x *= 0.5 * oversample;
441
target_size.y *= oversample;
442
443
return target_size;
444
}
445
446
Transform3D MobileVRInterface::get_camera_transform() {
447
_THREAD_SAFE_METHOD_
448
449
Transform3D transform_for_eye;
450
451
XRServer *xr_server = XRServer::get_singleton();
452
ERR_FAIL_NULL_V(xr_server, transform_for_eye);
453
454
if (initialized) {
455
float world_scale = xr_server->get_world_scale();
456
457
// just scale our origin point of our transform
458
Transform3D _head_transform = head_transform;
459
_head_transform.origin *= world_scale;
460
461
transform_for_eye = (xr_server->get_reference_frame()) * _head_transform;
462
}
463
464
return transform_for_eye;
465
}
466
467
Transform3D MobileVRInterface::get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) {
468
_THREAD_SAFE_METHOD_
469
470
Transform3D transform_for_eye;
471
472
XRServer *xr_server = XRServer::get_singleton();
473
ERR_FAIL_NULL_V(xr_server, transform_for_eye);
474
475
if (initialized) {
476
float world_scale = xr_server->get_world_scale();
477
478
// we don't need to check for the existence of our HMD, doesn't affect our values...
479
// note * 0.01 to convert cm to m and * 0.5 as we're moving half in each direction...
480
if (p_view == 0) {
481
transform_for_eye.origin.x = -(intraocular_dist * 0.01 * 0.5 * world_scale);
482
} else if (p_view == 1) {
483
transform_for_eye.origin.x = intraocular_dist * 0.01 * 0.5 * world_scale;
484
} else {
485
// should not have any other values..
486
};
487
488
// just scale our origin point of our transform
489
Transform3D _head_transform = head_transform;
490
_head_transform.origin *= world_scale;
491
492
transform_for_eye = p_cam_transform * (xr_server->get_reference_frame()) * _head_transform * transform_for_eye;
493
} else {
494
// huh? well just return what we got....
495
transform_for_eye = p_cam_transform;
496
};
497
498
return transform_for_eye;
499
}
500
501
Projection MobileVRInterface::get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) {
502
_THREAD_SAFE_METHOD_
503
504
Projection eye;
505
506
aspect = p_aspect;
507
eye.set_for_hmd(p_view + 1, p_aspect, intraocular_dist, display_width, display_to_lens, oversample, p_z_near, p_z_far);
508
509
return eye;
510
}
511
512
Vector<BlitToScreen> MobileVRInterface::post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) {
513
_THREAD_SAFE_METHOD_
514
515
Vector<BlitToScreen> blit_to_screen;
516
517
// We must have a valid render target.
518
ERR_FAIL_COND_V(!p_render_target.is_valid(), blit_to_screen);
519
520
// We will only output to screen if this is our main viewport.
521
if (p_screen_rect == Rect2()) {
522
// Warn the developer once, it's up to the developer to output to screen.
523
WARN_PRINT_ONCE("SubViewport used with MobileVRInterface, no output to screen");
524
525
return blit_to_screen;
526
}
527
528
Rect2 modified_screen_rect = Rect2(p_screen_rect.position + offset_rect.position * p_screen_rect.size, p_screen_rect.size * offset_rect.size);
529
530
// and add our blits
531
BlitToScreen blit;
532
blit.render_target = p_render_target;
533
blit.multi_view.use_layer = true;
534
blit.lens_distortion.apply = true;
535
blit.lens_distortion.k1 = k1;
536
blit.lens_distortion.k2 = k2;
537
blit.lens_distortion.upscale = oversample;
538
blit.lens_distortion.aspect_ratio = aspect;
539
540
// left eye
541
blit.dst_rect = modified_screen_rect;
542
blit.dst_rect.size.width *= 0.5;
543
blit.multi_view.layer = 0;
544
blit.lens_distortion.eye_center.x = ((-intraocular_dist / 2.0) + (display_width / 4.0)) / (display_width / 2.0);
545
blit_to_screen.push_back(blit);
546
547
// right eye
548
blit.dst_rect = modified_screen_rect;
549
blit.dst_rect.size.width *= 0.5;
550
blit.dst_rect.position.x += blit.dst_rect.size.width;
551
blit.multi_view.layer = 1;
552
blit.lens_distortion.eye_center.x = ((intraocular_dist / 2.0) - (display_width / 4.0)) / (display_width / 2.0);
553
blit_to_screen.push_back(blit);
554
555
return blit_to_screen;
556
}
557
558
void MobileVRInterface::process() {
559
_THREAD_SAFE_METHOD_
560
561
if (initialized) {
562
// update our head transform orientation
563
set_position_from_sensors();
564
565
// update our head transform position (should be constant)
566
head_transform.origin = Vector3(0.0, eye_height, 0.0);
567
568
if (head.is_valid()) {
569
// Set our head position, note in real space, reference frame and world scale is applied later
570
head->set_pose("default", head_transform, Vector3(), Vector3(), tracking_confidence);
571
}
572
};
573
}
574
575
RID MobileVRInterface::get_vrs_texture() {
576
PackedVector2Array eye_foci;
577
578
Size2 target_size = get_render_target_size();
579
real_t aspect_ratio = target_size.x / target_size.y;
580
uint32_t view_count = get_view_count();
581
582
for (uint32_t v = 0; v < view_count; v++) {
583
Projection cm = get_projection_for_view(v, aspect_ratio, 0.1, 1000.0);
584
Vector3 center = cm.xform(Vector3(0.0, 0.0, 999.0));
585
586
eye_foci.push_back(Vector2(center.x, center.y));
587
}
588
589
return xr_vrs.make_vrs_texture(target_size, eye_foci);
590
}
591
592
MobileVRInterface::MobileVRInterface() {}
593
594
MobileVRInterface::~MobileVRInterface() {
595
// and make sure we cleanup if we haven't already
596
if (is_initialized()) {
597
uninitialize();
598
};
599
}
600
601