A few fixes on the ARVR Server

(cherry picked from commit 5356423377)
This commit is contained in:
Bastiaan Olij 2018-03-15 22:33:55 +11:00 committed by Hein-Pieter van Braam
parent c20776945d
commit dfe6d42a01
3 changed files with 73 additions and 4 deletions

View File

@ -44,6 +44,7 @@ void ARVRServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_world_scale"), &ARVRServer::set_world_scale);
ClassDB::bind_method(D_METHOD("get_reference_frame"), &ARVRServer::get_reference_frame);
ClassDB::bind_method(D_METHOD("center_on_hmd", "rotation_mode", "keep_height"), &ARVRServer::center_on_hmd);
ClassDB::bind_method(D_METHOD("get_hmd_transform"), &ARVRServer::get_hmd_transform);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_scale"), "set_world_scale", "get_world_scale");
@ -54,8 +55,13 @@ void ARVRServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tracker_count"), &ARVRServer::get_tracker_count);
ClassDB::bind_method(D_METHOD("get_tracker", "idx"), &ARVRServer::get_tracker);
ClassDB::bind_method(D_METHOD("get_primary_interface"), &ARVRServer::get_primary_interface);
ClassDB::bind_method(D_METHOD("set_primary_interface", "interface"), &ARVRServer::set_primary_interface);
ClassDB::bind_method(D_METHOD("get_last_process_usec"), &ARVRServer::get_last_process_usec);
ClassDB::bind_method(D_METHOD("get_last_commit_usec"), &ARVRServer::get_last_commit_usec);
ClassDB::bind_method(D_METHOD("get_last_frame_usec"), &ARVRServer::get_last_frame_usec);
BIND_ENUM_CONSTANT(TRACKER_CONTROLLER);
BIND_ENUM_CONSTANT(TRACKER_BASESTATION);
BIND_ENUM_CONSTANT(TRACKER_ANCHOR);
@ -132,6 +138,14 @@ void ARVRServer::center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height)
};
};
Transform ARVRServer::get_hmd_transform() {
Transform hmd_transform;
if (primary_interface != NULL) {
hmd_transform = primary_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, hmd_transform);
};
return hmd_transform;
};
void ARVRServer::add_interface(const Ref<ARVRInterface> &p_interface) {
ERR_FAIL_COND(p_interface.is_null());
@ -314,6 +328,42 @@ void ARVRServer::clear_primary_interface_if(const Ref<ARVRInterface> &p_primary_
};
};
uint64_t ARVRServer::get_last_process_usec() {
return last_process_usec;
};
uint64_t ARVRServer::get_last_commit_usec() {
return last_commit_usec;
};
uint64_t ARVRServer::get_last_frame_usec() {
return last_frame_usec;
};
void ARVRServer::_process() {
/* called from visual_server_viewport.draw_viewports right before we start drawing our viewports */
/* mark for our frame timing */
last_process_usec = OS::get_singleton()->get_ticks_usec();
/* process all active interfaces */
for (int i = 0; i < interfaces.size(); i++) {
if (!interfaces[i].is_valid()) {
// ignore, not a valid reference
} else if (interfaces[i]->is_initialized()) {
interfaces[i]->process();
};
};
};
void ARVRServer::_mark_commit() {
/* time this */
last_commit_usec = OS::get_singleton()->get_ticks_usec();
/* now store our difference as we may overwrite last_process_usec before this is accessed */
last_frame_usec = last_commit_usec - last_process_usec;
};
ARVRServer::ARVRServer() {
singleton = this;
world_scale = 1.0;

View File

@ -31,6 +31,7 @@
#ifndef ARVR_SERVER_H
#define ARVR_SERVER_H
#include "os/os.h"
#include "os/thread_safe.h"
#include "reference.h"
#include "rid.h"
@ -84,6 +85,10 @@ private:
Transform world_origin; /* our world origin point, maps a location in our virtual world to the origin point in our real world tracking volume */
Transform reference_frame; /* our reference frame */
uint64_t last_process_usec; /* for frame timing, usec when we did our processing */
uint64_t last_commit_usec; /* for frame timing, usec when we finished committing both eyes */
uint64_t last_frame_usec; /* time it took between process and commiting, we should probably average this over the last x frames */
protected:
static ARVRServer *singleton;
@ -133,6 +138,11 @@ public:
Transform get_reference_frame() const;
void center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height);
/*
get_hmd_transform gets our hmd transform (centered between eyes) with most up to date tracking, relative to the origin
*/
Transform get_hmd_transform();
/*
Interfaces are objects that 'glue' Godot to an AR or VR SDK such as the Oculus SDK, OpenVR, OpenHMD, etc.
*/
@ -163,6 +173,13 @@ public:
ARVRPositionalTracker *get_tracker(int p_index) const;
ARVRPositionalTracker *find_by_type_and_id(TrackerType p_tracker_type, int p_tracker_id) const;
uint64_t get_last_process_usec();
uint64_t get_last_commit_usec();
uint64_t get_last_frame_usec();
void _process();
void _mark_commit();
ARVRServer();
~ARVRServer();
};

View File

@ -239,10 +239,9 @@ void VisualServerViewport::_draw_viewport(Viewport *p_viewport, ARVRInterface::E
void VisualServerViewport::draw_viewports() {
// get our arvr interface in case we need it
Ref<ARVRInterface> arvr_interface = ARVRServer::get_singleton()->get_primary_interface();
if (arvr_interface.is_valid()) {
// update our positioning information as late as possible...
arvr_interface->process();
}
// process all our active interfaces
ARVRServer::get_singleton()->_process();
clear_color = GLOBAL_GET("rendering/environment/default_clear_color");
@ -286,6 +285,9 @@ void VisualServerViewport::draw_viewports() {
_draw_viewport(vp, ARVRInterface::EYE_RIGHT);
arvr_interface->commit_for_eye(ARVRInterface::EYE_RIGHT, vp->render_target, vp->viewport_to_screen_rect);
}
// and for our frame timing, mark when we've finished commiting our eyes
ARVRServer::get_singleton()->_mark_commit();
} else {
VSG::rasterizer->set_current_render_target(vp->render_target);