diff options
Diffstat (limited to 'modules/mobile_vr')
-rw-r--r-- | modules/mobile_vr/SCsub | 6 | ||||
-rw-r--r-- | modules/mobile_vr/config.py | 3 | ||||
-rw-r--r-- | modules/mobile_vr/doc_classes/MobileVRInterface.xml | 8 | ||||
-rw-r--r-- | modules/mobile_vr/mobile_vr_interface.cpp | 53 | ||||
-rw-r--r-- | modules/mobile_vr/mobile_vr_interface.h | 14 | ||||
-rw-r--r-- | modules/mobile_vr/register_types.cpp | 2 | ||||
-rw-r--r-- | modules/mobile_vr/register_types.h | 5 |
7 files changed, 50 insertions, 41 deletions
diff --git a/modules/mobile_vr/SCsub b/modules/mobile_vr/SCsub index 4bd184f025..e6c43228b4 100644 --- a/modules/mobile_vr/SCsub +++ b/modules/mobile_vr/SCsub @@ -1,8 +1,8 @@ #!/usr/bin/env python -Import('env') -Import('env_modules') +Import("env") +Import("env_modules") env_mobile_vr = env_modules.Clone() -env_mobile_vr.add_source_files(env.modules_sources, '*.cpp') +env_mobile_vr.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/mobile_vr/config.py b/modules/mobile_vr/config.py index e85fa631dd..ee401c1a2a 100644 --- a/modules/mobile_vr/config.py +++ b/modules/mobile_vr/config.py @@ -1,13 +1,16 @@ def can_build(env, platform): return True + def configure(env): pass + def get_doc_classes(): return [ "MobileVRInterface", ] + def get_doc_path(): return "doc_classes" diff --git a/modules/mobile_vr/doc_classes/MobileVRInterface.xml b/modules/mobile_vr/doc_classes/MobileVRInterface.xml index 7552abe61d..120535bd41 100644 --- a/modules/mobile_vr/doc_classes/MobileVRInterface.xml +++ b/modules/mobile_vr/doc_classes/MobileVRInterface.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="MobileVRInterface" inherits="ARVRInterface" version="4.0"> +<class name="MobileVRInterface" inherits="XRInterface" version="4.0"> <brief_description> Generic mobile VR implementation. </brief_description> @@ -8,9 +8,9 @@ Note that even though there is no positional tracking, the camera will assume the headset is at a height of 1.85 meters. You can change this by setting [member eye_height]. You can initialise this interface as follows: [codeblock] - var interface = ARVRServer.find_interface("Native mobile") + var interface = XRServer.find_interface("Native mobile") if interface and interface.initialize(): - get_viewport().arvr = true + get_viewport().xr = true [/codeblock] </description> <tutorials> @@ -25,7 +25,7 @@ The width of the display in centimeters. </member> <member name="eye_height" type="float" setter="set_eye_height" getter="get_eye_height" default="1.85"> - The height at which the camera is placed in relation to the ground (i.e. [ARVROrigin] node). + The height at which the camera is placed in relation to the ground (i.e. [XROrigin3D] node). </member> <member name="iod" type="float" setter="set_iod" getter="get_iod" default="6.0"> The interocular distance, also known as the interpupillary distance. The distance between the pupils of the left and right eye. diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp index 2f1d95cd42..2f0a15f20b 100644 --- a/modules/mobile_vr/mobile_vr_interface.cpp +++ b/modules/mobile_vr/mobile_vr_interface.cpp @@ -29,16 +29,17 @@ /*************************************************************************/ #include "mobile_vr_interface.h" -#include "core/os/input.h" +#include "core/input/input_filter.h" #include "core/os/os.h" -#include "servers/visual/visual_server_globals.h" +#include "servers/display_server.h" +#include "servers/rendering/rendering_server_globals.h" StringName MobileVRInterface::get_name() const { return "Native mobile"; }; int MobileVRInterface::get_capabilities() const { - return ARVRInterface::ARVR_STEREO; + return XRInterface::XR_STEREO; }; Vector3 MobileVRInterface::scale_magneto(const Vector3 &p_magnetometer) { @@ -117,7 +118,7 @@ void MobileVRInterface::set_position_from_sensors() { float delta_time = (double)ticks_elapsed / 1000000.0; // few things we need - Input *input = Input::get_singleton(); + InputFilter *input = InputFilter::get_singleton(); Vector3 down(0.0, -1.0, 0.0); // Down is Y negative Vector3 north(0.0, 0.0, 1.0); // North is Z positive @@ -164,7 +165,7 @@ void MobileVRInterface::set_position_from_sensors() { rotate.rotate(orientation.get_axis(2), gyro.z * delta_time); orientation = rotate * orientation; - tracking_state = ARVRInterface::ARVR_NORMAL_TRACKING; + tracking_state = XRInterface::XR_NORMAL_TRACKING; }; ///@TODO improve this, the magnetometer is very fidgity sometimes flipping the axis for no apparent reason (probably a bug on my part) @@ -176,7 +177,7 @@ void MobileVRInterface::set_position_from_sensors() { transform_quat = transform_quat.slerp(acc_mag_quat, 0.1); orientation = Basis(transform_quat); - tracking_state = ARVRInterface::ARVR_NORMAL_TRACKING; + tracking_state = XRInterface::XR_NORMAL_TRACKING; } else if (has_grav) { // use gravity vector to make sure down is down... // transform gravity into our world space @@ -296,8 +297,8 @@ bool MobileVRInterface::is_initialized() const { }; bool MobileVRInterface::initialize() { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, false); + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, false); if (!initialized) { // reset our sensor data and orientation @@ -313,7 +314,7 @@ bool MobileVRInterface::initialize() { orientation = Basis(); // make this our primary interface - arvr_server->set_primary_interface(this); + xr_server->set_primary_interface(this); last_ticks = OS::get_singleton()->get_ticks_usec(); @@ -325,10 +326,10 @@ bool MobileVRInterface::initialize() { void MobileVRInterface::uninitialize() { if (initialized) { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - if (arvr_server != NULL) { + XRServer *xr_server = XRServer::get_singleton(); + if (xr_server != nullptr) { // no longer our primary interface - arvr_server->clear_primary_interface_if(this); + xr_server->clear_primary_interface_if(this); } initialized = false; @@ -339,7 +340,7 @@ Size2 MobileVRInterface::get_render_targetsize() { _THREAD_SAFE_METHOD_ // we use half our window size - Size2 target_size = OS::get_singleton()->get_window_size(); + Size2 target_size = DisplayServer::get_singleton()->window_get_size(); target_size.x *= 0.5 * oversample; target_size.y *= oversample; @@ -347,22 +348,22 @@ Size2 MobileVRInterface::get_render_targetsize() { return target_size; }; -Transform MobileVRInterface::get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) { +Transform MobileVRInterface::get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) { _THREAD_SAFE_METHOD_ Transform transform_for_eye; - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, transform_for_eye); + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, transform_for_eye); if (initialized) { - float world_scale = arvr_server->get_world_scale(); + float world_scale = xr_server->get_world_scale(); // we don't need to check for the existence of our HMD, doesn't effect our values... // note * 0.01 to convert cm to m and * 0.5 as we're moving half in each direction... - if (p_eye == ARVRInterface::EYE_LEFT) { + if (p_eye == XRInterface::EYE_LEFT) { transform_for_eye.origin.x = -(intraocular_dist * 0.01 * 0.5 * world_scale); - } else if (p_eye == ARVRInterface::EYE_RIGHT) { + } else if (p_eye == XRInterface::EYE_RIGHT) { transform_for_eye.origin.x = intraocular_dist * 0.01 * 0.5 * world_scale; } else { // for mono we don't reposition, we want our center position. @@ -373,7 +374,7 @@ Transform MobileVRInterface::get_transform_for_eye(ARVRInterface::Eyes p_eye, co hmd_transform.basis = orientation; hmd_transform.origin = Vector3(0.0, eye_height * world_scale, 0.0); - transform_for_eye = p_cam_transform * (arvr_server->get_reference_frame()) * hmd_transform * transform_for_eye; + transform_for_eye = p_cam_transform * (xr_server->get_reference_frame()) * hmd_transform * transform_for_eye; } else { // huh? well just return what we got.... transform_for_eye = p_cam_transform; @@ -382,12 +383,12 @@ Transform MobileVRInterface::get_transform_for_eye(ARVRInterface::Eyes p_eye, co return transform_for_eye; }; -CameraMatrix MobileVRInterface::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { +CameraMatrix MobileVRInterface::get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { _THREAD_SAFE_METHOD_ CameraMatrix eye; - if (p_eye == ARVRInterface::EYE_MONO) { + if (p_eye == XRInterface::EYE_MONO) { ///@TODO for now hardcode some of this, what is really needed here is that this needs to be in sync with the real cameras properties // which probably means implementing a specific class for iOS and Android. For now this is purely here as an example. // Note also that if you use a normal viewport with AR/VR turned off you can still use the tracker output of this interface @@ -395,13 +396,13 @@ CameraMatrix MobileVRInterface::get_projection_for_eye(ARVRInterface::Eyes p_eye // This will make more sense when we implement ARkit on iOS (probably a separate interface). eye.set_perspective(60.0, p_aspect, p_z_near, p_z_far, false); } else { - eye.set_for_hmd(p_eye == ARVRInterface::EYE_LEFT ? 1 : 2, p_aspect, intraocular_dist, display_width, display_to_lens, oversample, p_z_near, p_z_far); + eye.set_for_hmd(p_eye == XRInterface::EYE_LEFT ? 1 : 2, p_aspect, intraocular_dist, display_width, display_to_lens, oversample, p_z_near, p_z_far); }; return eye; }; -void MobileVRInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { +void MobileVRInterface::commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { _THREAD_SAFE_METHOD_ // We must have a valid render target @@ -416,9 +417,9 @@ void MobileVRInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_t // we output half a screen dest.size.x *= 0.5; - if (p_eye == ARVRInterface::EYE_LEFT) { + if (p_eye == XRInterface::EYE_LEFT) { eye_center.x = ((-intraocular_dist / 2.0) + (display_width / 4.0)) / (display_width / 2.0); - } else if (p_eye == ARVRInterface::EYE_RIGHT) { + } else if (p_eye == XRInterface::EYE_RIGHT) { dest.position.x = dest.size.x; eye_center.x = ((intraocular_dist / 2.0) - (display_width / 4.0)) / (display_width / 2.0); } diff --git a/modules/mobile_vr/mobile_vr_interface.h b/modules/mobile_vr/mobile_vr_interface.h index c762c9b799..3a9ed1314a 100644 --- a/modules/mobile_vr/mobile_vr_interface.h +++ b/modules/mobile_vr/mobile_vr_interface.h @@ -31,8 +31,8 @@ #ifndef MOBILE_VR_INTERFACE_H #define MOBILE_VR_INTERFACE_H -#include "servers/arvr/arvr_interface.h" -#include "servers/arvr/arvr_positional_tracker.h" +#include "servers/xr/xr_interface.h" +#include "servers/xr/xr_positional_tracker.h" /** @author Bastiaan Olij <mux213@gmail.com> @@ -47,8 +47,8 @@ more advanced interfaces. */ -class MobileVRInterface : public ARVRInterface { - GDCLASS(MobileVRInterface, ARVRInterface); +class MobileVRInterface : public XRInterface { + GDCLASS(MobileVRInterface, XRInterface); private: bool initialized; @@ -137,9 +137,9 @@ public: virtual Size2 get_render_targetsize(); virtual bool is_stereo(); - virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); - virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); + virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform); + virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); + virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); virtual void process(); virtual void notification(int p_what); diff --git a/modules/mobile_vr/register_types.cpp b/modules/mobile_vr/register_types.cpp index faf6c3b151..75638d47c4 100644 --- a/modules/mobile_vr/register_types.cpp +++ b/modules/mobile_vr/register_types.cpp @@ -37,7 +37,7 @@ void register_mobile_vr_types() { Ref<MobileVRInterface> mobile_vr; mobile_vr.instance(); - ARVRServer::get_singleton()->add_interface(mobile_vr); + XRServer::get_singleton()->add_interface(mobile_vr); } void unregister_mobile_vr_types() { diff --git a/modules/mobile_vr/register_types.h b/modules/mobile_vr/register_types.h index 602fae1f4e..33f608b6ed 100644 --- a/modules/mobile_vr/register_types.h +++ b/modules/mobile_vr/register_types.h @@ -28,5 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#ifndef MOBILE_VR_REGISTER_TYPES_H +#define MOBILE_VR_REGISTER_TYPES_H + void register_mobile_vr_types(); void unregister_mobile_vr_types(); + +#endif // MOBILE_VR_REGISTER_TYPES_H |