| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "servers/xr/xr_interface.h" |
| 34 |
#include "servers/xr/xr_positional_tracker.h" |
| 35 |
#include "servers/xr/xr_vrs.h" |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
class MobileVRInterface : public XRInterface { |
| 49 |
GDCLASS(MobileVRInterface, XRInterface); |
| 50 |
|
| 51 |
private: |
| 52 |
bool initialized = false; |
| 53 |
XRInterface::TrackingStatus tracking_state; |
| 54 |
XRPose::TrackingConfidence tracking_confidence = XRPose::XR_TRACKING_CONFIDENCE_NONE; |
| 55 |
|
| 56 |
|
| 57 |
double eye_height = 1.85; |
| 58 |
uint64_t last_ticks = 0; |
| 59 |
|
| 60 |
double intraocular_dist = 6.0; |
| 61 |
double display_width = 14.5; |
| 62 |
double display_to_lens = 4.0; |
| 63 |
double oversample = 1.5; |
| 64 |
|
| 65 |
Rect2 offset_rect = Rect2(0, 0, 1, 1); |
| 66 |
|
| 67 |
double k1 = 0.215; |
| 68 |
double k2 = 0.215; |
| 69 |
double aspect = 1.0; |
| 70 |
|
| 71 |
|
| 72 |
Ref<XRPositionalTracker> head; |
| 73 |
Transform3D head_transform; |
| 74 |
|
| 75 |
XRVRS xr_vrs; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
Vector3 scale_magneto(const Vector3 &p_magnetometer); |
| 83 |
Basis combine_acc_mag(const Vector3 &p_grav, const Vector3 &p_magneto); |
| 84 |
|
| 85 |
int mag_count = 0; |
| 86 |
bool has_gyro = false; |
| 87 |
bool sensor_first = false; |
| 88 |
Vector3 last_accerometer_data; |
| 89 |
Vector3 last_magnetometer_data; |
| 90 |
Vector3 mag_current_min; |
| 91 |
Vector3 mag_current_max; |
| 92 |
Vector3 mag_next_min; |
| 93 |
Vector3 mag_next_max; |
| 94 |
|
| 95 |
|
| 96 |
float floor_decimals(const float p_value, const float p_decimals) { |
| 97 |
float power_of_10 = std::pow(10.0f, p_decimals); |
| 98 |
return std::floor(p_value * power_of_10) / power_of_10; |
| 99 |
} |
| 100 |
|
| 101 |
Vector3 floor_decimals(const Vector3 &p_vector, const float p_decimals) { |
| 102 |
return Vector3(floor_decimals(p_vector.x, p_decimals), floor_decimals(p_vector.y, p_decimals), floor_decimals(p_vector.z, p_decimals)); |
| 103 |
} |
| 104 |
|
| 105 |
Vector3 low_pass(const Vector3 &p_vector, const Vector3 &p_last_vector, const float p_factor) { |
| 106 |
return p_vector + (p_factor * (p_last_vector - p_vector)); |
| 107 |
} |
| 108 |
|
| 109 |
Vector3 scrub(const Vector3 &p_vector, const Vector3 &p_last_vector, const float p_decimals, const float p_factor) { |
| 110 |
return low_pass(floor_decimals(p_vector, p_decimals), p_last_vector, p_factor); |
| 111 |
} |
| 112 |
|
| 113 |
void set_position_from_sensors(); |
| 114 |
|
| 115 |
protected: |
| 116 |
static void _bind_methods(); |
| 117 |
|
| 118 |
public: |
| 119 |
void set_eye_height(const double p_eye_height); |
| 120 |
double get_eye_height() const; |
| 121 |
|
| 122 |
void set_iod(const double p_iod); |
| 123 |
double get_iod() const; |
| 124 |
|
| 125 |
void set_display_width(const double p_display_width); |
| 126 |
double get_display_width() const; |
| 127 |
|
| 128 |
void set_offset_rect(const Rect2 &p_offset_rect); |
| 129 |
Rect2 get_offset_rect() const; |
| 130 |
|
| 131 |
void set_display_to_lens(const double p_display_to_lens); |
| 132 |
double get_display_to_lens() const; |
| 133 |
|
| 134 |
void set_oversample(const double p_oversample); |
| 135 |
double get_oversample() const; |
| 136 |
|
| 137 |
void set_k1(const double p_k1); |
| 138 |
double get_k1() const; |
| 139 |
|
| 140 |
void set_k2(const double p_k2); |
| 141 |
double get_k2() const; |
| 142 |
|
| 143 |
float get_vrs_min_radius() const; |
| 144 |
void set_vrs_min_radius(float p_vrs_min_radius); |
| 145 |
|
| 146 |
float get_vrs_strength() const; |
| 147 |
void set_vrs_strength(float p_vrs_strength); |
| 148 |
|
| 149 |
virtual StringName get_name() const override; |
| 150 |
virtual uint32_t get_capabilities() const override; |
| 151 |
|
| 152 |
virtual TrackingStatus get_tracking_status() const override; |
| 153 |
|
| 154 |
virtual bool is_initialized() const override; |
| 155 |
virtual bool initialize() override; |
| 156 |
virtual void uninitialize() override; |
| 157 |
virtual Dictionary get_system_info() override; |
| 158 |
|
| 159 |
virtual bool supports_play_area_mode(XRInterface::PlayAreaMode p_mode) override; |
| 160 |
virtual XRInterface::PlayAreaMode get_play_area_mode() const override; |
| 161 |
virtual bool set_play_area_mode(XRInterface::PlayAreaMode p_mode) override; |
| 162 |
|
| 163 |
virtual Size2 get_render_target_size() override; |
| 164 |
virtual uint32_t get_view_count() override; |
| 165 |
virtual Transform3D get_camera_transform() override; |
| 166 |
virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override; |
| 167 |
virtual Projection get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) override; |
| 168 |
virtual Vector<BlitToScreen> post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) override; |
| 169 |
|
| 170 |
virtual void process() override; |
| 171 |
|
| 172 |
virtual RID get_vrs_texture() override; |
| 173 |
|
| 174 |
MobileVRInterface(); |
| 175 |
~MobileVRInterface(); |
| 176 |
}; |