2017-10-07 13:51:17 +00:00
|
|
|
/*************************************************************************/
|
2020-04-08 14:47:36 +00:00
|
|
|
/* xr_interface_gdnative.cpp */
|
2017-10-07 13:51:17 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-10-07 13:51:17 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
#include "xr_interface_gdnative.h"
|
2020-04-28 13:19:37 +00:00
|
|
|
#include "core/input/input.h"
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "servers/rendering/rendering_server_globals.h"
|
2020-04-08 14:47:36 +00:00
|
|
|
#include "servers/xr/xr_positional_tracker.h"
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::_bind_methods() {
|
2019-06-01 13:42:22 +00:00
|
|
|
ADD_PROPERTY_DEFAULT("interface_is_initialized", false);
|
|
|
|
ADD_PROPERTY_DEFAULT("ar_is_anchor_detection_enabled", false);
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRInterfaceGDNative::XRInterfaceGDNative() {
|
2019-06-01 13:42:22 +00:00
|
|
|
print_verbose("Construct gdnative interface\n");
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
// we won't have our data pointer until our library gets set
|
2020-04-01 23:20:12 +00:00
|
|
|
data = nullptr;
|
2017-10-14 16:05:01 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
interface = nullptr;
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRInterfaceGDNative::~XRInterfaceGDNative() {
|
2019-06-01 13:42:22 +00:00
|
|
|
print_verbose("Destruct gdnative interface\n");
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
if (interface != nullptr && is_initialized()) {
|
2017-10-07 13:51:17 +00:00
|
|
|
uninitialize();
|
|
|
|
};
|
|
|
|
|
|
|
|
// cleanup after ourselves
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::cleanup() {
|
2020-04-01 23:20:12 +00:00
|
|
|
if (interface != nullptr) {
|
2017-10-14 16:05:01 +00:00
|
|
|
interface->destructor(data);
|
2020-04-01 23:20:12 +00:00
|
|
|
data = nullptr;
|
|
|
|
interface = nullptr;
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::set_interface(const godot_xr_interface_gdnative *p_interface) {
|
2017-10-14 22:58:36 +00:00
|
|
|
// this should only be called once, just being paranoid..
|
2017-10-14 16:05:01 +00:00
|
|
|
if (interface) {
|
2017-10-07 13:51:17 +00:00
|
|
|
cleanup();
|
2021-05-07 13:19:04 +00:00
|
|
|
interface = NULL;
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
// validate
|
|
|
|
ERR_FAIL_NULL(p_interface);
|
|
|
|
ERR_FAIL_COND_MSG(p_interface->version.major < 4, "This is an incompatible GDNative XR plugin.");
|
|
|
|
|
2017-10-14 22:58:36 +00:00
|
|
|
// bind to our interface
|
|
|
|
interface = p_interface;
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
// Now we do our constructing...
|
2017-10-14 16:05:01 +00:00
|
|
|
data = interface->constructor((godot_object *)this);
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
StringName XRInterfaceGDNative::get_name() const {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, StringName());
|
2017-10-14 16:05:01 +00:00
|
|
|
|
|
|
|
godot_string result = interface->get_name(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
StringName name = *(String *)&result;
|
|
|
|
|
|
|
|
godot_string_destroy(&result);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
int XRInterfaceGDNative::get_capabilities() const {
|
2017-10-07 13:51:17 +00:00
|
|
|
int capabilities;
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, 0); // 0 = None
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
capabilities = interface->get_capabilities(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
return capabilities;
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
bool XRInterfaceGDNative::get_anchor_detection_is_enabled() const {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, false);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2019-06-01 13:42:22 +00:00
|
|
|
return interface->get_anchor_detection_is_enabled(data);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND(interface == nullptr);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
interface->set_anchor_detection_is_enabled(data, p_enable);
|
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
int XRInterfaceGDNative::get_camera_feed_id() {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, 0);
|
2017-08-20 14:17:24 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
return (unsigned int)interface->get_camera_feed_id(data);
|
2017-08-20 14:17:24 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
uint32_t XRInterfaceGDNative::get_view_count() {
|
|
|
|
uint32_t view_count;
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, 1);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
view_count = interface->get_view_count(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
return view_count;
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
bool XRInterfaceGDNative::is_initialized() const {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, false);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2019-06-01 13:42:22 +00:00
|
|
|
return interface->is_initialized(data);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
bool XRInterfaceGDNative::initialize() {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, false);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2019-06-01 13:42:22 +00:00
|
|
|
bool initialized = interface->initialize(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
if (initialized) {
|
|
|
|
// if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
if ((xr_server != nullptr) && (xr_server->get_primary_interface() == nullptr)) {
|
|
|
|
xr_server->set_primary_interface(this);
|
2017-10-07 13:51:17 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::uninitialize() {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND(interface == nullptr);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
if (xr_server != nullptr) {
|
2017-10-07 13:51:17 +00:00
|
|
|
// Whatever happens, make sure this is no longer our primary interface
|
2020-04-08 14:47:36 +00:00
|
|
|
xr_server->clear_primary_interface_if(this);
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
interface->uninitialize(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
Size2 XRInterfaceGDNative::get_render_targetsize() {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, Size2());
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-11-04 00:50:05 +00:00
|
|
|
godot_vector2 result = interface->get_render_targetsize(data);
|
2017-10-14 16:05:01 +00:00
|
|
|
Vector2 *vec = (Vector2 *)&result;
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
return *vec;
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
Transform3D XRInterfaceGDNative::get_camera_transform() {
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D *ret;
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, Transform3D());
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
godot_transform3d t = interface->get_camera_transform(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
ret = (Transform3D *)&t;
|
2017-10-14 16:05:01 +00:00
|
|
|
|
|
|
|
return *ret;
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
Transform3D XRInterfaceGDNative::get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) {
|
|
|
|
Transform3D *ret;
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(interface == nullptr, Transform3D());
|
|
|
|
|
|
|
|
godot_transform3d t = interface->get_transform_for_view(data, (int)p_view, (godot_transform3d *)&p_cam_transform);
|
|
|
|
|
|
|
|
ret = (Transform3D *)&t;
|
|
|
|
|
|
|
|
return *ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraMatrix XRInterfaceGDNative::get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) {
|
2017-10-07 13:51:17 +00:00
|
|
|
CameraMatrix cm;
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, CameraMatrix());
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
interface->fill_projection_for_view(data, (godot_real_t *)cm.matrix, (godot_int)p_view, p_aspect, p_z_near, p_z_far);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
return cm;
|
|
|
|
}
|
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
Vector<BlitToScreen> XRInterfaceGDNative::commit_views(RID p_render_target, const Rect2 &p_screen_rect) {
|
|
|
|
// possibly move this as a member variable and add a callback to populate?
|
|
|
|
Vector<BlitToScreen> blit_to_screen;
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(interface == nullptr, blit_to_screen);
|
|
|
|
|
|
|
|
// must implement
|
|
|
|
interface->commit_views(data, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect);
|
|
|
|
|
|
|
|
return blit_to_screen;
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
unsigned int XRInterfaceGDNative::get_external_texture_for_eye(XRInterface::Eyes p_eye) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(interface == nullptr, 0);
|
2019-03-30 13:03:49 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
return (unsigned int)interface->get_external_texture_for_eye(data, (godot_int)p_eye);
|
2019-03-30 13:03:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND(interface == nullptr);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
interface->commit_for_eye(data, (godot_int)p_eye, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect);
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::process() {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND(interface == nullptr);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
interface->process(data);
|
2017-10-07 13:51:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRInterfaceGDNative::notification(int p_what) {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND(interface == nullptr);
|
2019-03-13 09:43:21 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
interface->notification(data, p_what);
|
2019-03-13 09:43:21 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 13:51:17 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// some helper callbacks
|
|
|
|
|
2017-10-14 16:05:01 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void GDAPI godot_xr_register_interface(const godot_xr_interface_gdnative *p_interface) {
|
|
|
|
// Must be on a version 4 plugin
|
|
|
|
ERR_FAIL_COND_MSG(p_interface->version.major < 4, "GDNative XR interfaces build for Godot 3.x are not supported.");
|
2018-05-26 00:03:25 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
Ref<XRInterfaceGDNative> new_interface;
|
2021-06-17 22:03:09 +00:00
|
|
|
new_interface.instantiate();
|
2020-04-08 14:47:36 +00:00
|
|
|
new_interface->set_interface((const godot_xr_interface_gdnative *)p_interface);
|
|
|
|
XRServer::get_singleton()->add_interface(new_interface);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
godot_real_t GDAPI godot_xr_get_worldscale() {
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL_V(xr_server, 1.0);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
return xr_server->get_world_scale();
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-05-03 09:47:42 +00:00
|
|
|
godot_transform3d GDAPI godot_xr_get_reference_frame() {
|
|
|
|
godot_transform3d reference_frame;
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D *reference_frame_ptr = (Transform3D *)&reference_frame;
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
if (xr_server != nullptr) {
|
|
|
|
*reference_frame_ptr = xr_server->get_reference_frame();
|
2017-10-07 13:51:17 +00:00
|
|
|
} else {
|
2020-10-17 05:08:21 +00:00
|
|
|
memnew_placement(&reference_frame, Transform3D);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
return reference_frame;
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void GDAPI godot_xr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect) {
|
2017-10-07 13:51:17 +00:00
|
|
|
// blits out our texture as is, handy for preview display of one of the eyes that is already rendered with lens distortion on an external HMD
|
2020-04-08 14:47:36 +00:00
|
|
|
XRInterface::Eyes eye = (XRInterface::Eyes)p_eye;
|
2020-02-13 14:53:32 +00:00
|
|
|
#if 0
|
2017-10-07 13:51:17 +00:00
|
|
|
RID *render_target = (RID *)p_render_target;
|
2020-02-13 14:53:32 +00:00
|
|
|
#endif
|
2017-10-07 13:51:17 +00:00
|
|
|
Rect2 screen_rect = *(Rect2 *)p_rect;
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
if (eye == XRInterface::EYE_LEFT) {
|
2017-10-07 13:51:17 +00:00
|
|
|
screen_rect.size.x /= 2.0;
|
2020-04-08 14:47:36 +00:00
|
|
|
} else if (p_eye == XRInterface::EYE_RIGHT) {
|
2017-10-07 13:51:17 +00:00
|
|
|
screen_rect.size.x /= 2.0;
|
|
|
|
screen_rect.position.x += screen_rect.size.x;
|
|
|
|
}
|
2019-06-22 16:34:26 +00:00
|
|
|
#ifndef _MSC_VER
|
2019-06-16 02:45:24 +00:00
|
|
|
#warning this needs to be redone
|
2019-06-22 16:34:26 +00:00
|
|
|
#endif
|
2019-06-16 02:45:24 +00:00
|
|
|
#if 0
|
2020-03-27 18:21:27 +00:00
|
|
|
RSG::rasterizer->blit_render_target_to_screen(*render_target, screen_rect, 0);
|
2019-06-16 02:45:24 +00:00
|
|
|
#endif
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
godot_int GDAPI godot_xr_get_texid(godot_rid *p_render_target) {
|
2017-10-07 13:51:17 +00:00
|
|
|
// In order to send off our textures to display on our hardware we need the opengl texture ID instead of the render target RID
|
|
|
|
// This is a handy function to expose that.
|
2020-02-13 14:53:32 +00:00
|
|
|
#if 0
|
2017-10-07 13:51:17 +00:00
|
|
|
RID *render_target = (RID *)p_render_target;
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RID eye_texture = RSG::storage->render_target_get_texture(*render_target);
|
2020-02-13 14:53:32 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-22 16:34:26 +00:00
|
|
|
#ifndef _MSC_VER
|
2019-06-11 18:43:37 +00:00
|
|
|
#warning need to obtain this ID again
|
2019-06-22 16:34:26 +00:00
|
|
|
#endif
|
2020-03-27 18:21:27 +00:00
|
|
|
uint32_t texid = 0; //RS::get_singleton()->texture_get_texid(eye_texture);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
return texid;
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
|
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL_V(xr_server, 0);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-28 13:19:37 +00:00
|
|
|
Input *input = Input::get_singleton();
|
2017-10-07 13:51:17 +00:00
|
|
|
ERR_FAIL_NULL_V(input, 0);
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> new_tracker;
|
2021-06-17 22:03:09 +00:00
|
|
|
new_tracker.instantiate();
|
2020-12-10 11:16:14 +00:00
|
|
|
new_tracker->set_tracker_name(p_device_name);
|
|
|
|
new_tracker->set_tracker_type(XRServer::TRACKER_CONTROLLER);
|
2017-10-07 13:51:17 +00:00
|
|
|
if (p_hand == 1) {
|
2020-12-10 11:16:14 +00:00
|
|
|
new_tracker->set_tracker_hand(XRPositionalTracker::TRACKER_HAND_LEFT);
|
2017-10-07 13:51:17 +00:00
|
|
|
} else if (p_hand == 2) {
|
2020-12-10 11:16:14 +00:00
|
|
|
new_tracker->set_tracker_hand(XRPositionalTracker::TRACKER_HAND_RIGHT);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
// also register as joystick...
|
|
|
|
int joyid = input->get_unused_joy_id();
|
|
|
|
if (joyid != -1) {
|
|
|
|
new_tracker->set_joy_id(joyid);
|
|
|
|
input->joy_connection_changed(joyid, true, p_device_name, "");
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
if (p_tracks_orientation) {
|
|
|
|
Basis orientation;
|
|
|
|
new_tracker->set_orientation(orientation);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
if (p_tracks_position) {
|
|
|
|
Vector3 position;
|
|
|
|
new_tracker->set_position(position);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
// add our tracker to our server and remember its pointer
|
2020-04-08 14:47:36 +00:00
|
|
|
xr_server->add_tracker(new_tracker);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
// note, this ID is only unique within controllers!
|
|
|
|
return new_tracker->get_tracker_id();
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void GDAPI godot_xr_remove_controller(godot_int p_controller_id) {
|
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL(xr_server);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-28 13:19:37 +00:00
|
|
|
Input *input = Input::get_singleton();
|
2017-10-07 13:51:17 +00:00
|
|
|
ERR_FAIL_NULL(input);
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> remove_tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id);
|
|
|
|
if (remove_tracker.is_valid()) {
|
2017-10-07 13:51:17 +00:00
|
|
|
// unset our joystick if applicable
|
|
|
|
int joyid = remove_tracker->get_joy_id();
|
|
|
|
if (joyid != -1) {
|
|
|
|
input->joy_connection_changed(joyid, false, "", "");
|
|
|
|
remove_tracker->set_joy_id(-1);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
|
|
|
// remove our tracker from our server
|
2020-04-08 14:47:36 +00:00
|
|
|
xr_server->remove_tracker(remove_tracker);
|
2021-03-29 10:15:53 +00:00
|
|
|
remove_tracker.unref();
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-05-03 09:47:42 +00:00
|
|
|
void GDAPI godot_xr_set_controller_transform(godot_int p_controller_id, godot_transform3d *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL(xr_server);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id);
|
|
|
|
if (tracker.is_valid()) {
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D *transform = (Transform3D *)p_transform;
|
2017-10-07 13:51:17 +00:00
|
|
|
if (p_tracks_orientation) {
|
|
|
|
tracker->set_orientation(transform->basis);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
if (p_tracks_position) {
|
2017-11-28 12:28:35 +00:00
|
|
|
tracker->set_rw_position(transform->origin);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed) {
|
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL(xr_server);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-28 13:19:37 +00:00
|
|
|
Input *input = Input::get_singleton();
|
2017-10-07 13:51:17 +00:00
|
|
|
ERR_FAIL_NULL(input);
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id);
|
|
|
|
if (tracker.is_valid()) {
|
2017-10-07 13:51:17 +00:00
|
|
|
int joyid = tracker->get_joy_id();
|
|
|
|
if (joyid != -1) {
|
2021-03-25 20:56:12 +00:00
|
|
|
input->joy_button(joyid, (JoyButton)p_button, p_is_pressed);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real_t p_value, godot_bool p_can_be_negative) {
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL(xr_server);
|
2017-10-07 13:51:17 +00:00
|
|
|
|
2020-04-28 13:19:37 +00:00
|
|
|
Input *input = Input::get_singleton();
|
2017-10-07 13:51:17 +00:00
|
|
|
ERR_FAIL_NULL(input);
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id);
|
|
|
|
if (tracker.is_valid()) {
|
2017-10-07 13:51:17 +00:00
|
|
|
int joyid = tracker->get_joy_id();
|
|
|
|
if (joyid != -1) {
|
2020-05-13 22:27:34 +00:00
|
|
|
Input::JoyAxisValue jx;
|
2017-10-07 13:51:17 +00:00
|
|
|
jx.min = p_can_be_negative ? -1 : 0;
|
|
|
|
jx.value = p_value;
|
2021-03-25 20:56:12 +00:00
|
|
|
input->joy_axis(joyid, (JoyAxis)p_axis, jx);
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-01 10:46:37 +00:00
|
|
|
|
2021-05-07 13:19:04 +00:00
|
|
|
godot_real_t GDAPI godot_xr_get_controller_rumble(godot_int p_controller_id) {
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *xr_server = XRServer::get_singleton();
|
|
|
|
ERR_FAIL_NULL_V(xr_server, 0.0);
|
2017-11-01 10:46:37 +00:00
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id);
|
|
|
|
if (tracker.is_valid()) {
|
2017-11-01 10:46:37 +00:00
|
|
|
return tracker->get_rumble();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0.0;
|
|
|
|
}
|
2017-10-14 16:05:01 +00:00
|
|
|
}
|