diff options
author | BastiaanOlij <mux213@gmail.com> | 2017-04-23 22:10:41 +1000 |
---|---|---|
committer | BastiaanOlij <mux213@gmail.com> | 2017-07-28 10:39:15 +1000 |
commit | d2ba2d08733647dc345db123469988966c8b31b0 (patch) | |
tree | 878817443d5929948e1b05e1d1eb39fe2091cd40 /servers/arvr | |
parent | 411f09a512d5847fc9c6270439308d1e3093f211 (diff) |
Adding base classes and structures for ARVR support
Added ArVrScriptInterface
Added ARVRCamera, ARVRController and ARVROrigin helper objects
Diffstat (limited to 'servers/arvr')
-rw-r--r-- | servers/arvr/SCsub | 7 | ||||
-rw-r--r-- | servers/arvr/arvr_interface.cpp | 82 | ||||
-rw-r--r-- | servers/arvr/arvr_interface.h | 89 | ||||
-rw-r--r-- | servers/arvr/arvr_positional_tracker.cpp | 142 | ||||
-rw-r--r-- | servers/arvr/arvr_positional_tracker.h | 85 | ||||
-rw-r--r-- | servers/arvr/arvr_script_interface.cpp | 127 | ||||
-rw-r--r-- | servers/arvr/arvr_script_interface.h | 47 |
7 files changed, 579 insertions, 0 deletions
diff --git a/servers/arvr/SCsub b/servers/arvr/SCsub new file mode 100644 index 0000000000..ccc76e823f --- /dev/null +++ b/servers/arvr/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.servers_sources, "*.cpp") + +Export('env') diff --git a/servers/arvr/arvr_interface.cpp b/servers/arvr/arvr_interface.cpp new file mode 100644 index 0000000000..81eb011932 --- /dev/null +++ b/servers/arvr/arvr_interface.cpp @@ -0,0 +1,82 @@ +/*************************************************************************/ +/* arvr_interface.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "arvr_interface.h" + +void ARVRInterface::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_name"), &ARVRInterface::get_name); + + ClassDB::bind_method(D_METHOD("is_primary"), &ARVRInterface::is_primary); + ClassDB::bind_method(D_METHOD("set_is_primary", "enable"), &ARVRInterface::set_is_primary); + + ClassDB::bind_method(D_METHOD("is_installed"), &ARVRInterface::is_installed); + ClassDB::bind_method(D_METHOD("hmd_is_present"), &ARVRInterface::hmd_is_present); + ClassDB::bind_method(D_METHOD("supports_hmd"), &ARVRInterface::supports_hmd); + ClassDB::bind_method(D_METHOD("is_initialized"), &ARVRInterface::is_initialized); + ClassDB::bind_method(D_METHOD("initialize"), &ARVRInterface::initialize); + ClassDB::bind_method(D_METHOD("uninitialize"), &ARVRInterface::uninitialize); + + ClassDB::bind_method(D_METHOD("get_recommended_render_targetsize"), &ARVRInterface::get_recommended_render_targetsize); + + // These are now purely used internally, we may expose them again if we expose CameraMatrix through Variant but reduz is not a fan for good reasons :) + // ClassDB::bind_method(D_METHOD("get_transform_for_eye", "eye", "cam_transform"), &ARVRInterface::get_transform_for_eye); + // ClassDB::bind_method(D_METHOD("get_projection_for_eye", "eye"), &ARVRInterface::get_projection_for_eye); + // ClassDB::bind_method(D_METHOD("commit_for_eye", "node:viewport"), &ARVRInterface::commit_for_eye); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "primary"), "set_is_primary", "is_primary"); + + BIND_CONSTANT(EYE_MONO); + BIND_CONSTANT(EYE_LEFT); + BIND_CONSTANT(EYE_RIGHT); +}; + +StringName ARVRInterface::get_name() const { + return "Unknown"; +}; + +bool ARVRInterface::is_primary() { + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL_V(arvr_server, false); + + return arvr_server->get_primary_interface() == this; +}; + +void ARVRInterface::set_is_primary(bool p_is_primary) { + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL(arvr_server); + + if (p_is_primary) { + ERR_FAIL_COND(!is_initialized()); + ERR_FAIL_COND(!supports_hmd()); + + arvr_server->set_primary_interface(this); + } else { + arvr_server->clear_primary_interface_if(this); + }; +}; diff --git a/servers/arvr/arvr_interface.h b/servers/arvr/arvr_interface.h new file mode 100644 index 0000000000..e405499fbb --- /dev/null +++ b/servers/arvr/arvr_interface.h @@ -0,0 +1,89 @@ +/*************************************************************************/ +/* arvr_interface.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef ARVR_INTERFACE_H +#define ARVR_INTERFACE_H + +#include "core/math/camera_matrix.h" +#include "os/thread_safe.h" +#include "scene/main/viewport.h" +#include "servers/arvr_server.h" + +/** + @author Bastiaan Olij <mux213@gmail.com> + + The ARVR interface is a template class ontop of which we build interface to differt AR, VR and tracking SDKs. + The idea is that we subclass this class, implement the logic, and then instantiate a singleton of each interface + when Godot starts. These instances do not initialize themselves but register themselves with the AR/VR server. + + If the user wants to enable AR/VR the choose the interface they want to use and initialize it. + + Note that we may make this into a fully instantiable class for GDNative support. +*/ + +class ARVRInterface : public Reference { + GDCLASS(ARVRInterface, Reference); + +protected: + _THREAD_SAFE_CLASS_ + + static void _bind_methods(); + +public: + enum Eyes { + EYE_MONO, /* my son says we should call this EYE_CYCLOPS */ + EYE_LEFT, + EYE_RIGHT + }; + + virtual StringName get_name() const; + + bool is_primary(); + void set_is_primary(bool p_is_primary); + + virtual bool is_installed() = 0; /* returns true if the middle ware related to this interface has been installed */ + virtual bool hmd_is_present() = 0; /* returns true if our HMD is connected */ + virtual bool supports_hmd() = 0; /* returns true is this interface handles output to an HMD or only handles positioning */ + + virtual bool is_initialized() = 0; /* returns true if we've initialized this interface */ + virtual bool initialize() = 0; /* initialize this interface, if this has an HMD it becomes the primary interface */ + virtual void uninitialize() = 0; /* deinitialize this interface */ + + virtual Size2 get_recommended_render_targetsize() = 0; /* returns the recommended render target size per eye for this device */ + virtual bool is_stereo() = 0; /* returns true if this interface requires stereo rendering (for VR HMDs) or mono rendering (for mobile AR) */ + virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) = 0; /* get each eyes camera transform, also implement EYE_MONO */ + virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) = 0; /* get each eyes projection matrix */ + virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */ + + virtual void process() = 0; +}; + +VARIANT_ENUM_CAST(ARVRInterface::Eyes); + +#endif diff --git a/servers/arvr/arvr_positional_tracker.cpp b/servers/arvr/arvr_positional_tracker.cpp new file mode 100644 index 0000000000..4215363d16 --- /dev/null +++ b/servers/arvr/arvr_positional_tracker.cpp @@ -0,0 +1,142 @@ +/*************************************************************************/ +/* arvr_postional_tracker.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "arvr_positional_tracker.h" +#include "core/os/input.h" + +void ARVRPositionalTracker::_bind_methods() { + // this class is read only from GDScript, so we only have access to getters.. + ClassDB::bind_method(D_METHOD("get_type"), &ARVRPositionalTracker::get_type); + ClassDB::bind_method(D_METHOD("get_name"), &ARVRPositionalTracker::get_name); + ClassDB::bind_method(D_METHOD("get_joy_id"), &ARVRPositionalTracker::get_joy_id); + ClassDB::bind_method(D_METHOD("get_tracks_orientation"), &ARVRPositionalTracker::get_tracks_orientation); + ClassDB::bind_method(D_METHOD("get_orientation"), &ARVRPositionalTracker::get_orientation); + ClassDB::bind_method(D_METHOD("get_tracks_position"), &ARVRPositionalTracker::get_tracks_position); + ClassDB::bind_method(D_METHOD("get_position"), &ARVRPositionalTracker::get_position); + ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &ARVRPositionalTracker::get_transform); +}; + +void ARVRPositionalTracker::set_type(ARVRServer::TrackerType p_type) { + if (type != p_type) { + type = p_type; + + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL(arvr_server); + + // get a tracker id for our type + tracker_id = arvr_server->get_free_tracker_id_for_type(p_type); + } +}; + +ARVRServer::TrackerType ARVRPositionalTracker::get_type() const { + return type; +}; + +void ARVRPositionalTracker::set_name(const String p_name) { + name = p_name; +}; + +StringName ARVRPositionalTracker::get_name() const { + return name; +}; + +int ARVRPositionalTracker::get_tracker_id() const { + return tracker_id; +}; + +void ARVRPositionalTracker::set_joy_id(int p_joy_id) { + joy_id = p_joy_id; +}; + +int ARVRPositionalTracker::get_joy_id() const { + return joy_id; +}; + +bool ARVRPositionalTracker::get_tracks_orientation() const { + return tracks_orientation; +}; + +void ARVRPositionalTracker::set_orientation(const Basis &p_orientation) { + _THREAD_SAFE_METHOD_ + + tracks_orientation = true; // obviously we have this + orientation = p_orientation; +}; + +Basis ARVRPositionalTracker::get_orientation() const { + _THREAD_SAFE_METHOD_ + + return orientation; +}; + +bool ARVRPositionalTracker::get_tracks_position() const { + return tracks_position; +}; + +void ARVRPositionalTracker::set_position(const Vector3 &p_position) { + _THREAD_SAFE_METHOD_ + + tracks_position = true; // obviously we have this + position = p_position; +}; + +Vector3 ARVRPositionalTracker::get_position() const { + _THREAD_SAFE_METHOD_ + + return position; +}; + +Transform ARVRPositionalTracker::get_transform(bool p_adjust_by_reference_frame) const { + Transform new_transform; + + new_transform.basis = get_orientation(); + new_transform.origin = get_position(); + + if (p_adjust_by_reference_frame) { + ARVRServer *arvr_server = ARVRServer::get_singleton(); + ERR_FAIL_NULL_V(arvr_server, new_transform); + + new_transform = arvr_server->get_reference_frame() * new_transform; + }; + + return new_transform; +}; + +ARVRPositionalTracker::ARVRPositionalTracker() { + type = ARVRServer::TRACKER_UNKNOWN; + name = "Unknown"; + joy_id = -1; + tracker_id = 0; + tracks_orientation = false; + tracks_position = false; +}; + +ARVRPositionalTracker::~ARVRPositionalTracker(){ + +}; diff --git a/servers/arvr/arvr_positional_tracker.h b/servers/arvr/arvr_positional_tracker.h new file mode 100644 index 0000000000..e8c613b29d --- /dev/null +++ b/servers/arvr/arvr_positional_tracker.h @@ -0,0 +1,85 @@ +/*************************************************************************/ +/* arvr_positional_tracker.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef ARVR_POSITIONAL_TRACKER_H +#define ARVR_POSITIONAL_TRACKER_H + +#include "os/thread_safe.h" +#include "servers/arvr_server.h" + +/** + @author Bastiaan Olij <mux213@gmail.com> + + The positional tracker object as an object that represents the position and orientation of a tracked object like a controller or headset. + An AR/VR Interface will registered the trackers it manages with our AR/VR server and update its position and orientation. + This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking. + + @TODO: + - create subclass of spatial node that uses one of our positional trackers to automatically determine its position +*/ + +class ARVRPositionalTracker : public Object { + GDCLASS(ARVRPositionalTracker, Object); + _THREAD_SAFE_CLASS_ + +private: + ARVRServer::TrackerType type; // type of tracker + StringName name; // (unique) name of the tracker + int tracker_id; // tracker index id that is unique per type + int joy_id; // if we also have a related joystick entity, the id of the joystick + bool tracks_orientation; // do we track orientation? + Basis orientation; // our orientation + bool tracks_position; // do we track position? + Vector3 position; // our position + +protected: + static void _bind_methods(); + +public: + void set_type(ARVRServer::TrackerType p_type); + ARVRServer::TrackerType get_type() const; + void set_name(const String p_name); + StringName get_name() const; + int get_tracker_id() const; + void set_joy_id(int p_joy_id); + int get_joy_id() const; + bool get_tracks_orientation() const; + void set_orientation(const Basis &p_orientation); + Basis get_orientation() const; + bool get_tracks_position() const; + void set_position(const Vector3 &p_position); + Vector3 get_position() const; + + Transform get_transform(bool p_adjust_by_reference_frame) const; + + ARVRPositionalTracker(); + ~ARVRPositionalTracker(); +}; + +#endif diff --git a/servers/arvr/arvr_script_interface.cpp b/servers/arvr/arvr_script_interface.cpp new file mode 100644 index 0000000000..16e607920e --- /dev/null +++ b/servers/arvr/arvr_script_interface.cpp @@ -0,0 +1,127 @@ +#include "arvr_script_interface.h" + +ARVRScriptInterface::ARVRScriptInterface() { + // testing + printf("Construct script interface"); +} + +ARVRScriptInterface::~ARVRScriptInterface() { + if (is_initialized()) { + uninitialize(); + }; + + // testing + printf("Destruct script interface"); +} + +StringName ARVRScriptInterface::get_name() const { + if (get_script_instance() && get_script_instance()->has_method("get_name")) { + return get_script_instance()->call("get_name"); + } else { + // just return something for now + return "ARVR Script interface"; + } +} + +bool ARVRScriptInterface::is_installed() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_installed")), false); + return get_script_instance()->call("is_installed"); +} + +bool ARVRScriptInterface::hmd_is_present() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("hmd_is_present")), false); + return get_script_instance()->call("hmd_is_present"); +} + +bool ARVRScriptInterface::supports_hmd() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("supports_hmd")), false); + return get_script_instance()->call("supports_hmd"); +} + +bool ARVRScriptInterface::is_stereo() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_stereo")), false); + return get_script_instance()->call("is_stereo"); +} + +bool ARVRScriptInterface::is_initialized() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_initialized")), false); + return get_script_instance()->call("is_initialized"); +} + +bool ARVRScriptInterface::initialize() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("initialize")), false); + return get_script_instance()->call("initialize"); +} + +void ARVRScriptInterface::uninitialize() { + ARVRServer *arvr_server = ARVRServer::get_singleton(); + if (arvr_server != NULL) { + // Whatever happens, make sure this is no longer our primary interface + arvr_server->clear_primary_interface_if(this); + } + + ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("uninitialize"))); + get_script_instance()->call("uninitialize"); +} + +Size2 ARVRScriptInterface::get_recommended_render_targetsize() { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_recommended_render_targetsize")), Size2()); + return get_script_instance()->call("get_recommended_render_targetsize"); +} + +Transform ARVRScriptInterface::get_transform_for_eye(Eyes p_eye, const Transform &p_cam_transform) { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_transform_for_eye")), Transform()); + return get_script_instance()->call("get_transform_for_eye", p_eye, p_cam_transform); +} + +// Suggestion from Reduz, as we can't return a CameraMatrix, return a PoolVector with our 16 floats +PoolVector<float> ARVRScriptInterface::_get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { + ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_projection_for_eye")), PoolVector<float>()); + return get_script_instance()->call("_get_projection_for_eye", p_eye, p_aspect, p_z_near, p_z_far); +} + +CameraMatrix ARVRScriptInterface::get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { + CameraMatrix cm; + int i = 0; + int j = 0; + + PoolVector<float> cm_as_floats = _get_projection_for_eye(p_eye, p_aspect, p_z_near, p_z_far); + + for (int k = 0; k < cm_as_floats.size() && i < 4; k++) { + cm.matrix[i][j] = cm_as_floats[k]; + j++; + if (j == 4) { + j = 0; + i++; + }; + }; + + return cm; +} + +void ARVRScriptInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { + ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("commit_for_eye"))); + get_script_instance()->call("commit_for_eye"); +} + +void ARVRScriptInterface::process() { + ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("process"))); + get_script_instance()->call("process"); +} + +void ARVRScriptInterface::_bind_methods() { + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_installed")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "hmd_is_present")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "supports_hmd")); + + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_initialized")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "initialize")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("uninitialize")); + + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_stereo")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::VECTOR2, "get_recommended_render_targetsize")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::TRANSFORM, "get_transform_for_eye", PropertyInfo(Variant::INT, "eye"), PropertyInfo(Variant::TRANSFORM, "cam_transform"))); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("_get_projection_for_eye")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("commit_for_eye", PropertyInfo(Variant::INT, "eye"), PropertyInfo(Variant::_RID, "render_target"))); + ClassDB::add_virtual_method(get_class_static(), MethodInfo("process")); +} diff --git a/servers/arvr/arvr_script_interface.h b/servers/arvr/arvr_script_interface.h new file mode 100644 index 0000000000..04ca33901a --- /dev/null +++ b/servers/arvr/arvr_script_interface.h @@ -0,0 +1,47 @@ +#ifndef SCRIPT_INTERFACE_H +#define SCRIPT_INTERFACE_H + +#include "arvr_interface.h" + +/** + @authors Hinsbart & Karroffel + + This subclass of our AR/VR interface forms a bridge to GDNative. +*/ + +class ARVRScriptInterface : public ARVRInterface { + GDCLASS(ARVRScriptInterface, ARVRInterface); + +protected: + static void _bind_methods(); + +public: + ARVRScriptInterface(); + ~ARVRScriptInterface(); + + virtual StringName get_name() const; + + virtual bool is_installed(); + virtual bool hmd_is_present(); + virtual bool supports_hmd(); + + virtual bool is_initialized(); + virtual bool initialize(); + virtual void uninitialize(); + + virtual Size2 get_recommended_render_targetsize(); + virtual bool is_stereo(); + virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); + + // we expose a PoolVector<float> version of this function to GDNative + PoolVector<float> _get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); + + // and a CameraMatrix version to ARVRServer + 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 void process(); +}; + +#endif // SCRIPT_INTERFACE_H |