Redoing the ARVR GDNative interface as module and tighter implementation

This commit is contained in:
BastiaanOlij 2017-10-08 00:51:17 +11:00
parent 4585239a4b
commit cc37d43f86
17 changed files with 1121 additions and 317 deletions

View file

@ -1,118 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ARVRScriptInterface" inherits="ARVRInterface" category="Core" version="3.0.alpha.custom_build">
<brief_description>
Base class for GDNative based ARVR interfaces.
</brief_description>
<description>
This class is used as a base class/interface class for implementing GDNative based ARVR interfaces and as a result exposes more of the internals of the ARVR server.
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<method name="_get_projection_for_eye" qualifiers="virtual">
<return type="void">
</return>
<description>
Should return the projection 4x4 matrix for the requested eye.
</description>
</method>
<method name="commit_for_eye" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="eye" type="int">
</argument>
<argument index="1" name="render_target" type="RID">
</argument>
<description>
Outputs a finished render buffer to the AR/VR device for the given eye.
</description>
</method>
<method name="get_anchor_detection_is_enabled" qualifiers="virtual">
<return type="bool">
</return>
<description>
Returns true if achor detection is enabled (AR only).
</description>
</method>
<method name="get_capabilities" qualifiers="virtual">
<return type="int">
</return>
<description>
Returns a combination of flags providing information about the capabilities of this interface.
</description>
</method>
<method name="get_recommended_render_targetsize" qualifiers="virtual">
<return type="Vector2">
</return>
<description>
Returns the size at which we should render our scene to get optimal quality on the output device.
</description>
</method>
<method name="get_tracking_status" qualifiers="virtual">
<return type="int">
</return>
<description>
If supported, returns the status of our tracking. This will allow you to provide feedback to the user whether there are issues with positional tracking.
</description>
</method>
<method name="get_transform_for_eye" qualifiers="virtual">
<return type="Transform">
</return>
<argument index="0" name="eye" type="int">
</argument>
<argument index="1" name="cam_transform" type="Transform">
</argument>
<description>
Get the location and orientation transform used when rendering a specific eye.
</description>
</method>
<method name="initialize" qualifiers="virtual">
<return type="bool">
</return>
<description>
Initialize this interface.
</description>
</method>
<method name="is_initialized" qualifiers="virtual">
<return type="bool">
</return>
<description>
Returns true if this interface has been initialized and is active.
</description>
</method>
<method name="is_stereo" qualifiers="virtual">
<return type="bool">
</return>
<description>
Returns true if we require stereoscopic rendering for this interface.
</description>
</method>
<method name="process" qualifiers="virtual">
<return type="void">
</return>
<description>
Gets called before rendering each frame so tracking data gets updated in time.
</description>
</method>
<method name="set_anchor_detection_is_enabled" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="enabled" type="bool">
</argument>
<description>
Enables anchor detection, this is used on AR interfaces and enables the extra logic that will detect planes, features, objects, etc. and adds/modifies anchor points.
</description>
</method>
<method name="uninitialize" qualifiers="virtual">
<return type="void">
</return>
<description>
Turn this interface off.
</description>
</method>
</methods>
<constants>
</constants>
</class>

View file

@ -45,6 +45,7 @@
#include "input_map.h"
#include "io/resource_loader.h"
#include "scene/main/scene_tree.h"
#include "servers/arvr_server.h"
#include "servers/audio_server.h"
#include "io/resource_loader.h"
@ -82,6 +83,7 @@ static InputMap *input_map = NULL;
static bool _start_success = false;
static ScriptDebugger *script_debugger = NULL;
AudioServer *audio_server = NULL;
ARVRServer *arvr_server = NULL;
static MessageQueue *message_queue = NULL;
static Performance *performance = NULL;
@ -939,11 +941,14 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
OS::get_singleton()->set_window_position(init_custom_pos);
}
//right moment to create and initialize the audio server
// right moment to create and initialize the audio server
audio_server = memnew(AudioServer);
audio_server->init();
// also init our arvr_server from here
arvr_server = memnew(ARVRServer);
OS::get_singleton()->set_use_vsync(use_vsync);
register_core_singletons();
@ -1775,6 +1780,11 @@ void Main::cleanup() {
memdelete(audio_server);
}
if (arvr_server) {
// cleanup now before we pull the rug from underneath...
memdelete(arvr_server);
}
unregister_driver_types();
unregister_module_types();
unregister_scene_types();

View file

@ -12,6 +12,8 @@ gdn_env.add_source_files(env.modules_sources, "nativescript/*.cpp")
gdn_env.Append(CPPPATH=['#modules/gdnative/include/'])
SConscript("nativearvr/SCsub")
def _spaced(e):
return e if e[-1] == '*' else e + ' '
@ -22,6 +24,7 @@ def _build_gdnative_api_struct_header(api):
'#define GODOT_GDNATIVE_API_STRUCT_H',
'',
'#include <gdnative/gdnative.h>',
'#include <nativearvr/godot_nativearvr.h>',
'#include <nativescript/godot_nativescript.h>',
'',
'#define GDNATIVE_API_INIT(options) do { extern const godot_gdnative_api_struct *_gdnative_wrapper_api_struct; _gdnative_wrapper_api_struct = options->api_struct; } while (0)',

View file

@ -6,7 +6,7 @@ def configure(env):
env.use_ptrcall = True
def get_doc_classes():
return ["GDNative", "GDNativeLibrary", "NativeScript"]
return ["GDNative", "GDNativeLibrary", "NativeScript", "ARVRInterfaceGDNative"]
def get_doc_path():
return "doc_classes"

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ARVRInterfaceGDNative" inherits="ARVRInterface" category="Core" version="3.0.alpha.custom_build">
<brief_description>
GDNative wrapper for an ARVR interface
</brief_description>
<description>
This is a wrapper class for GDNative implementations of the ARVR interface. To use a GDNative ARVR interface simply instantiate this object and set your GDNative library containing the ARVR interface implementation.
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<method name="set_gdnative_library">
<return type="void">
</return>
<argument index="0" name="library" type="GDNativeLibrary">
</argument>
<description>
Bind this GDNative library to our interface. The library must be a GDNative ARVR Interface for this to work.
</description>
</method>
</methods>
<constants>
</constants>
</class>

View file

@ -5229,6 +5229,78 @@
"arguments": [
["godot_object *", "p_instance"]
]
},
{
"name": "godot_arvr_get_worldscale",
"return_type": "godot_real",
"arguments": []
},
{
"name": "godot_arvr_get_reference_frame",
"return_type": "godot_transform",
"arguments": []
},
{
"name": "godot_arvr_blit",
"return_type": "void",
"arguments": [
["int", "p_eye"],
["godot_rid *", "p_render_target"],
["godot_rect2 *", "p_screen_rect"]
]
},
{
"name": "godot_arvr_get_texid",
"return_type": "godot_int",
"arguments": [
["godot_rid *", "p_render_target"]
]
},
{
"name": "godot_arvr_add_controller",
"return_type": "godot_int",
"arguments": [
["char *", "p_device_name"],
["godot_int", "p_hand"],
["godot_bool", "p_tracks_orientation"],
["godot_bool", "p_tracks_position"]
]
},
{
"name": "godot_arvr_remove_controller",
"return_type": "void",
"arguments": [
["godot_int", "p_controller_id"]
]
},
{
"name": "godot_arvr_set_controller_transform",
"return_type": "void",
"arguments": [
["godot_int", "p_controller_id"],
["godot_transform *", "p_transform"],
["godot_bool", "p_tracks_orientation"],
["godot_bool", "p_tracks_position"]
]
},
{
"name": "godot_arvr_set_controller_button",
"return_type": "void",
"arguments": [
["godot_int", "p_controller_id"],
["godot_int", "p_button"],
["godot_bool", "p_is_pressed"]
]
},
{
"name": "godot_arvr_set_controller_axis",
"return_type": "void",
"arguments": [
["godot_int", "p_controller_id"],
["godot_int", "p_exis"],
["godot_real", "p_value"],
["godot_bool", "p_can_be_negative"]
]
}
]
}

View file

@ -0,0 +1,58 @@
/*************************************************************************/
/* godot_nativearvr.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://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 GODOT_NATIVEARVR_H
#define GODOT_NATIVEARVR_H
#include <gdnative/gdnative.h>
#ifdef __cplusplus
extern "C" {
#endif
// helper functions to access ARVRServer data
godot_real GDAPI godot_arvr_get_worldscale();
godot_transform GDAPI godot_arvr_get_reference_frame();
// helper functions for rendering
void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect);
godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target);
// helper functions for updating ARVR controllers
godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position);
void GDAPI godot_arvr_remove_controller(godot_int p_controller_id);
void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position);
void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed);
void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative);
#ifdef __cplusplus
}
#endif
#endif /* !GODOT_NATIVEARVR_H */

View file

@ -0,0 +1,13 @@
#!/usr/bin/env python
import os
import methods
Import('env')
Import('env_modules')
env_arvr_gdnative = env_modules.Clone()
env_arvr_gdnative.Append(CPPPATH=['#modules/gdnative/include/'])
env_arvr_gdnative.add_source_files(env.modules_sources, '*.cpp')

View file

@ -0,0 +1,394 @@
/*************************************************************************/
/* arvr_interface_gdnative.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://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_gdnative.h"
#include "main/input_default.h"
#include "servers/arvr/arvr_positional_tracker.h"
#include "servers/visual/visual_server_global.h"
ARVRInterfaceGDNative::ARVRInterfaceGDNative() {
// testing
printf("Construct gdnative interface\n");
// we won't have our data pointer until our library gets set
data = NULL;
}
ARVRInterfaceGDNative::~ARVRInterfaceGDNative() {
printf("Destruct gdnative interface\n");
if (is_initialized()) {
uninitialize();
};
// cleanup after ourselves
cleanup();
}
void ARVRInterfaceGDNative::cleanup() {
if (data != NULL) {
library->call_native_raw("arvr_call_destructor", "godot_arvr_destructor", data, 0, NULL, NULL);
data = NULL;
};
if (library.is_valid()) {
library->terminate();
};
};
void ARVRInterfaceGDNative::set_gdnative_library(Ref<GDNativeLibrary> p_library) {
if (library.is_null()) {
library.instance();
} else {
cleanup();
};
library->set_library(p_library);
library->initialize();
// Now we do our constructing...
void *parameters[1];
parameters[0] = (void *)this;
library->call_native_raw("arvr_call_constructor", "godot_arvr_constructor", NULL, 1, parameters, &data);
}
StringName ARVRInterfaceGDNative::get_name() const {
StringName name;
ERR_FAIL_COND_V(data == NULL, StringName());
const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_string", "godot_arvr_get_name", data, 0, NULL, &name);
return name;
}
int ARVRInterfaceGDNative::get_capabilities() const {
int capabilities;
ERR_FAIL_COND_V(data == NULL, 0); // 0 = None
const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_int", "godot_arvr_get_capabilities", data, 0, NULL, &capabilities);
return capabilities;
};
bool ARVRInterfaceGDNative::get_anchor_detection_is_enabled() const {
bool enabled;
ERR_FAIL_COND_V(data == NULL, false);
const_cast<GDNative *>(library.ptr())->call_native_raw("arvr_return_bool", "godot_arvr_get_anchor_detection_is_enabled", data, 0, NULL, &enabled);
return enabled;
};
void ARVRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) {
void *parameters[1];
ERR_FAIL_COND(data == NULL);
parameters[0] = (void *)&p_enable;
library->call_native_raw("arvr_set_bool", "godot_arvr_set_anchor_detection_is_enabled", data, 1, parameters, NULL);
};
bool ARVRInterfaceGDNative::is_stereo() {
bool stereo;
ERR_FAIL_COND_V(data == NULL, false);
library->call_native_raw("arvr_return_bool", "godot_arvr_is_stereo", data, 0, NULL, &stereo);
return stereo;
};
bool ARVRInterfaceGDNative::is_initialized() {
bool initialized;
ERR_FAIL_COND_V(data == NULL, false);
library->call_native_raw("arvr_return_bool", "godot_arvr_is_initialized", data, 0, NULL, &initialized);
return initialized;
};
bool ARVRInterfaceGDNative::initialize() {
bool initialized;
ERR_FAIL_COND_V(data == NULL, false);
library->call_native_raw("arvr_return_bool", "godot_arvr_initialize", data, 0, NULL, &initialized);
if (initialized) {
// if we successfully initialize our interface and we don't have a primary interface yet, this becomes our primary interface
ARVRServer *arvr_server = ARVRServer::get_singleton();
if ((arvr_server != NULL) && (arvr_server->get_primary_interface() == NULL)) {
arvr_server->set_primary_interface(this);
};
};
return initialized;
}
void ARVRInterfaceGDNative::uninitialize() {
ERR_FAIL_COND(data == NULL);
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);
}
library->call_native_raw("arvr_call_method", "godot_arvr_uninitialize", data, 0, NULL, NULL);
}
Size2 ARVRInterfaceGDNative::get_recommended_render_targetsize() {
Size2 size;
ERR_FAIL_COND_V(data == NULL, Size2());
library->call_native_raw("arvr_return_vector2", "godot_arvr_get_recommended_render_targetsize", data, 0, NULL, &size);
return size;
}
Transform ARVRInterfaceGDNative::get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) {
void *parameters[2];
Transform ret;
ERR_FAIL_COND_V(data == NULL, Transform());
parameters[0] = (void *)&p_eye;
parameters[1] = (void *)&p_cam_transform;
library->call_native_raw("arvr_return_transform_for_eye", "godot_arvr_get_transform_for_eye", data, 2, parameters, &ret);
return ret;
}
CameraMatrix ARVRInterfaceGDNative::get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) {
void *parameters[5];
CameraMatrix cm;
ERR_FAIL_COND_V(data == NULL, CameraMatrix());
parameters[0] = (void *)cm.matrix;
parameters[1] = (void *)&p_eye;
parameters[2] = (void *)&p_aspect;
parameters[3] = (void *)&p_z_near;
parameters[4] = (void *)&p_z_far;
library->call_native_raw("arvr_call_fill_projection_for_eye", "godot_arvr_fill_projection_for_eye", data, 5, parameters, NULL);
return cm;
}
void ARVRInterfaceGDNative::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) {
void *parameters[3];
ERR_FAIL_COND(data == NULL);
parameters[0] = (void *)&p_eye;
parameters[1] = (void *)&p_render_target;
parameters[2] = (void *)&p_screen_rect;
library->call_native_raw("arvr_call_commit_for_eye", "godot_arvr_commit_for_eye", data, 3, parameters, NULL);
}
void ARVRInterfaceGDNative::process() {
ERR_FAIL_COND(data == NULL);
library->call_native_raw("arvr_call_method", "godot_arvr_process", data, 0, NULL, NULL);
}
void ARVRInterfaceGDNative::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_gdnative_library", "library"), &ARVRInterfaceGDNative::set_gdnative_library);
}
/////////////////////////////////////////////////////////////////////////////////////
// some helper callbacks
godot_real GDAPI godot_arvr_get_worldscale() {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL_V(arvr_server, 1.0);
return arvr_server->get_world_scale();
};
godot_transform GDAPI godot_arvr_get_reference_frame() {
godot_transform reference_frame;
Transform *reference_frame_ptr = (Transform *)&reference_frame;
ARVRServer *arvr_server = ARVRServer::get_singleton();
if (arvr_server != NULL) {
*reference_frame_ptr = arvr_server->get_reference_frame();
} else {
godot_transform_new_identity(&reference_frame);
};
return reference_frame;
};
void GDAPI godot_arvr_blit(godot_int p_eye, godot_rid *p_render_target, godot_rect2 *p_rect) {
// 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
ARVRInterface::Eyes eye = (ARVRInterface::Eyes)p_eye;
RID *render_target = (RID *)p_render_target;
Rect2 screen_rect = *(Rect2 *)p_rect;
if (eye == ARVRInterface::EYE_LEFT) {
screen_rect.size.x /= 2.0;
} else if (p_eye == ARVRInterface::EYE_RIGHT) {
screen_rect.size.x /= 2.0;
screen_rect.position.x += screen_rect.size.x;
}
VSG::rasterizer->set_current_render_target(RID());
VSG::rasterizer->blit_render_target_to_screen(*render_target, screen_rect, 0);
};
godot_int GDAPI godot_arvr_get_texid(godot_rid *p_render_target) {
// 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.
RID *render_target = (RID *)p_render_target;
RID eye_texture = VSG::storage->render_target_get_texture(*render_target);
uint32_t texid = VS::get_singleton()->texture_get_texid(eye_texture);
return texid;
};
godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL_V(arvr_server, 0);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL_V(input, 0);
ARVRPositionalTracker *new_tracker = memnew(ARVRPositionalTracker);
new_tracker->set_name(p_device_name);
new_tracker->set_type(ARVRServer::TRACKER_CONTROLLER);
if (p_hand == 1) {
new_tracker->set_hand(ARVRPositionalTracker::TRACKER_LEFT_HAND);
} else if (p_hand == 2) {
new_tracker->set_hand(ARVRPositionalTracker::TRACKER_RIGHT_HAND);
};
// 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, "");
};
if (p_tracks_orientation) {
Basis orientation;
new_tracker->set_orientation(orientation);
};
if (p_tracks_position) {
Vector3 position;
new_tracker->set_position(position);
};
// add our tracker to our server and remember its pointer
arvr_server->add_tracker(new_tracker);
// note, this ID is only unique within controllers!
return new_tracker->get_tracker_id();
};
void GDAPI godot_arvr_remove_controller(godot_int p_controller_id) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL(input);
ARVRPositionalTracker *remove_tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (remove_tracker != NULL) {
// 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);
};
// remove our tracker from our server
arvr_server->remove_tracker(remove_tracker);
memdelete(remove_tracker);
};
};
void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker != NULL) {
Transform *transform = (Transform *)p_transform;
if (p_tracks_orientation) {
tracker->set_orientation(transform->basis);
};
if (p_tracks_position) {
tracker->set_position(transform->origin);
};
};
};
void GDAPI godot_arvr_set_controller_button(godot_int p_controller_id, godot_int p_button, godot_bool p_is_pressed) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL(input);
ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker != NULL) {
int joyid = tracker->get_joy_id();
if (joyid != -1) {
input->joy_button(joyid, p_button, p_is_pressed);
};
};
};
void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative) {
ARVRServer *arvr_server = ARVRServer::get_singleton();
ERR_FAIL_NULL(arvr_server);
InputDefault *input = (InputDefault *)Input::get_singleton();
ERR_FAIL_NULL(input);
ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
if (tracker != NULL) {
int joyid = tracker->get_joy_id();
if (joyid != -1) {
InputDefault::JoyAxis jx;
jx.min = p_can_be_negative ? -1 : 0;
jx.value = p_value;
input->joy_axis(joyid, p_axis, jx);
};
};
};

View file

@ -0,0 +1,88 @@
/*************************************************************************/
/* arvr_interface_gdnative.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://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_GDNATIVE_H
#define ARVR_INTERFACE_GDNATIVE_H
#include "modules/gdnative/gdnative.h"
#include "servers/arvr/arvr_interface.h"
/**
@authors Hinsbart & Karroffel & Mux213
This subclass of our AR/VR interface forms a bridge to GDNative.
*/
class ARVRInterfaceGDNative : public ARVRInterface {
GDCLASS(ARVRInterfaceGDNative, ARVRInterface);
void cleanup();
protected:
Ref<GDNative> library;
void *data;
static void _bind_methods();
public:
/** general interface information **/
ARVRInterfaceGDNative();
~ARVRInterfaceGDNative();
void set_gdnative_library(Ref<GDNativeLibrary> p_library);
virtual StringName get_name() const;
virtual int get_capabilities() const;
virtual bool is_initialized();
virtual bool initialize();
virtual void uninitialize();
/** specific to AR **/
virtual bool get_anchor_detection_is_enabled() const;
virtual void set_anchor_detection_is_enabled(bool p_enable);
/** rendering and internal **/
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(ARVRInterface::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 // ARVR_INTERFACE_GDNATIVE_H

View file

@ -0,0 +1,5 @@
def can_build(platform):
return True
def configure(env):
pass

View file

@ -0,0 +1,414 @@
/*************************************************************************/
/* register_types.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://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 "register_types.h"
#include "arvr_interface_gdnative.h"
#include "core/os/os.h"
void arvr_call_constructor(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
void *(*proc)(godot_object *);
proc = (void *(*)(godot_object *))library_proc;
godot_object *this_object = (godot_object *)p_args[0];
void *p = proc(this_object);
void **return_ptr = (void **)r_return;
*return_ptr = p;
};
void arvr_call_destructor(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
void (*proc)(void *);
proc = (void (*)(void *))library_proc;
proc(p_data);
};
void arvr_return_string(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
godot_string (*proc)(void *);
proc = (godot_string(*)(void *))library_proc;
godot_string s = proc(p_data);
StringName *return_ptr = (StringName *)r_return;
String *returned_string = (String *)&s;
*return_ptr = *returned_string;
godot_string_destroy(&s);
};
void arvr_return_int(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
godot_int (*proc)(void *);
proc = (godot_int(*)(void *))library_proc;
godot_int i = proc(p_data);
int *return_ptr = (int *)r_return;
*return_ptr = i;
};
void arvr_return_bool(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
godot_bool (*proc)(void *);
proc = (godot_bool(*)(void *))library_proc;
godot_bool b = proc(p_data);
int *return_ptr = (int *)r_return;
*return_ptr = b;
};
void arvr_set_bool(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
void (*proc)(void *, bool);
proc = (void (*)(void *, bool))library_proc;
bool *set_bool = (bool *)p_args[0];
proc(p_data, *set_bool);
};
void arvr_call_method(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
godot_bool (*proc)(void *);
proc = (godot_bool(*)(void *))library_proc;
proc(p_data);
};
void arvr_return_vector2(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
godot_vector2 (*proc)(void *);
proc = (godot_vector2(*)(void *))library_proc;
godot_vector2 v = proc(p_data);
godot_vector2 *return_ptr = (godot_vector2 *)r_return;
*return_ptr = v;
};
void arvr_return_transform_for_eye(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
godot_transform (*proc)(void *, int, godot_transform *);
proc = (godot_transform(*)(void *, int, godot_transform *))library_proc;
int *eye = (int *)p_args[0];
godot_transform *camera_transform = (godot_transform *)p_args[1];
godot_transform t = proc(p_data, *eye, camera_transform);
godot_transform *return_ptr = (godot_transform *)r_return;
*return_ptr = t;
};
void arvr_call_fill_projection_for_eye(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
void (*proc)(void *, real_t *, int, real_t, real_t, real_t);
proc = (void (*)(void *, real_t *, int, real_t, real_t, real_t))library_proc;
real_t *projection = (real_t *)p_args[0]; // <-- we'll be writing into this buffer, must have enough space for 16 floats!
int *eye = (int *)p_args[1];
real_t *aspect = (real_t *)p_args[2];
real_t *zn = (real_t *)p_args[3];
real_t *zf = (real_t *)p_args[4];
proc(p_data, projection, *eye, *aspect, *zn, *zf);
};
void arvr_call_commit_for_eye(
void *p_handle,
godot_string *p_proc_name,
void *p_data,
int p_num_args,
void **p_args,
void *r_return) {
if (p_handle == NULL) {
ERR_PRINT("No valid library handle, can't call standard varcall procedure");
return;
}
void *library_proc;
Error err = OS::get_singleton()->get_dynamic_library_symbol_handle(
p_handle,
*(String *)p_proc_name,
library_proc,
true); // we roll our own message
if (err != OK) {
ERR_PRINT((String("GDNative procedure \"" + *(String *)p_proc_name) + "\" does not exists and can't be called").utf8().get_data());
return;
}
void (*proc)(void *, int, godot_rid *, godot_rect2 *);
proc = (void (*)(void *, int, godot_rid *, godot_rect2 *))library_proc;
int *eye = (int *)p_args[0];
godot_rid *rid = (godot_rid *)p_args[1];
godot_rect2 *screen_rect = (godot_rect2 *)p_args[2];
proc(p_data, *eye, rid, screen_rect);
};
void register_nativearvr_types() {
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_constructor", arvr_call_constructor);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_destructor", arvr_call_destructor);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_string", arvr_return_string);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_int", arvr_return_int);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_bool", arvr_return_bool);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_set_bool", arvr_set_bool);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_method", arvr_call_method);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_vector2", arvr_return_vector2);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_return_transform_for_eye", arvr_return_transform_for_eye);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_fill_projection_for_eye", arvr_call_fill_projection_for_eye);
GDNativeCallRegistry::singleton->register_native_raw_call_type("arvr_call_commit_for_eye", arvr_call_commit_for_eye);
ClassDB::register_class<ARVRInterfaceGDNative>();
}
void unregister_nativearvr_types() {
}

View file

@ -0,0 +1,32 @@
/*************************************************************************/
/* register_types.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://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. */
/*************************************************************************/
void register_nativearvr_types();
void unregister_nativearvr_types();

View file

@ -35,6 +35,7 @@
#include "io/resource_loader.h"
#include "io/resource_saver.h"
#include "nativearvr/register_types.h"
#include "nativescript/register_types.h"
#include "core/engine.h"
@ -202,6 +203,7 @@ void register_gdnative_types() {
GDNativeCallRegistry::singleton->register_native_raw_call_type("gdnative_singleton_call", cb_singleton_call);
register_nativearvr_types();
register_nativescript_types();
// run singletons
@ -249,6 +251,7 @@ void unregister_gdnative_types() {
}
singleton_gdnatives.clear();
unregister_nativearvr_types();
unregister_nativescript_types();
memdelete(GDNativeCallRegistry::singleton);
@ -280,4 +283,4 @@ void unregister_gdnative_types() {
print_line(String("vector2:\t") + itos(sizeof(Vector2)));
print_line(String("vector3:\t") + itos(sizeof(Vector3)));
*/
}
}

View file

@ -1,136 +0,0 @@
#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";
}
}
int ARVRScriptInterface::get_capabilities() const {
ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_capabilities")), ARVRInterface::ARVR_NONE);
return get_script_instance()->call("get_capabilities");
};
ARVRInterface::Tracking_status ARVRScriptInterface::get_tracking_status() const {
ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_tracking_status")), ARVRInterface::ARVR_NOT_TRACKING);
int status = get_script_instance()->call("get_tracking_status");
return (ARVRInterface::Tracking_status)status;
}
bool ARVRScriptInterface::get_anchor_detection_is_enabled() const {
ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_anchor_detection_is_enabled")), false);
return get_script_instance()->call("get_anchor_detection_is_enabled");
};
void ARVRScriptInterface::set_anchor_detection_is_enabled(bool p_enable) {
ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("set_anchor_detection_is_enabled")));
get_script_instance()->call("set_anchor_detection_is_enabled");
};
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::INT, "get_capabilities"));
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::INT, "get_tracking_status"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "get_anchor_detection_is_enabled"));
ClassDB::add_virtual_method(get_class_static(), MethodInfo("set_anchor_detection_is_enabled", PropertyInfo(Variant::BOOL, "enabled")));
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"));
}

View file

@ -1,52 +0,0 @@
#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:
/** general interface information **/
ARVRScriptInterface();
~ARVRScriptInterface();
virtual StringName get_name() const;
virtual int get_capabilities() const;
virtual bool is_initialized();
virtual bool initialize();
virtual void uninitialize();
ARVRInterface::Tracking_status get_tracking_status() const; /* get the status of our current tracking */
/** specific to AR **/
virtual bool get_anchor_detection_is_enabled() const;
virtual void set_anchor_detection_is_enabled(bool p_enable);
/** rendering and internal **/
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

View file

@ -32,7 +32,6 @@
#include "arvr/arvr_interface.h"
#include "arvr/arvr_positional_tracker.h"
#include "arvr/arvr_script_interface.h"
#include "arvr_server.h"
#include "audio/audio_effect.h"
#include "audio/audio_stream.h"
@ -74,10 +73,8 @@ static void _debugger_get_resource_usage(List<ScriptDebuggerRemote::ResourceUsag
}
ShaderTypes *shader_types = NULL;
ARVRServer *arvr_server = NULL;
void register_server_types() {
arvr_server = memnew(ARVRServer);
ClassDB::register_virtual_class<VisualServer>();
ClassDB::register_class<AudioServer>();
@ -95,7 +92,6 @@ void register_server_types() {
ClassDB::register_virtual_class<ARVRInterface>();
ClassDB::register_class<ARVRPositionalTracker>();
ClassDB::register_class<ARVRScriptInterface>();
ClassDB::register_virtual_class<AudioStream>();
ClassDB::register_virtual_class<AudioStreamPlayback>();
@ -152,9 +148,5 @@ void register_server_types() {
void unregister_server_types() {
//@TODO move this into iPhone/Android implementation? just have this here for testing...
// mobile_interface = NULL;
memdelete(shader_types);
memdelete(arvr_server);
}