Skip to content

Commit

Permalink
Merge pull request #18 from patrickdown/change-xrorigin3d-to-t5gameboard
Browse files Browse the repository at this point in the history
Change to using TiltFiveGameboard instead of XROrigin3D where needed.
  • Loading branch information
patrickdown committed Jun 20, 2023
2 parents f32f006 + af481c7 commit e95ef3d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions extension/src/TiltFiveGameboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using godot::ClassDB;
using godot::PropertyInfo;
using godot::D_METHOD;
using godot::Variant;

void TiltFiveGameboard::_bind_methods() {
// Methods.
Expand Down
4 changes: 0 additions & 4 deletions extension/src/TiltFiveGameboard.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#ifndef TILT_FIVE_XR_ORIGIN_H
#define TILT_FIVE_XR_ORIGIN_H

#include "TiltFiveXRInterface.h"

#include <godot_cpp/classes/xr_origin3d.hpp>



using godot::XROrigin3D;

class TiltFiveGameboard : public XROrigin3D {
Expand Down
24 changes: 12 additions & 12 deletions extension/src/TiltFiveXRInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "TiltFiveXRInterface.h"
#include "TiltFiveGameboard.h"
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/rendering_server.hpp>
Expand All @@ -15,7 +14,7 @@ void TiltFiveXRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("start_service", "application_id", "application_version"), &TiltFiveXRInterface::start_service);
ClassDB::bind_method(D_METHOD("stop_service"), &TiltFiveXRInterface::stop_service);
ClassDB::bind_method(D_METHOD("reserve_glasses", "glasses_id", "display_name"), &TiltFiveXRInterface::reserve_glasses);
ClassDB::bind_method(D_METHOD("start_display", "glasses_id", "viewport", "xr_origin"), &TiltFiveXRInterface::start_display);
ClassDB::bind_method(D_METHOD("start_display", "glasses_id", "viewport", "gameboard"), &TiltFiveXRInterface::start_display);
ClassDB::bind_method(D_METHOD("stop_display", "glasses_id"), &TiltFiveXRInterface::stop_display);
ClassDB::bind_method(D_METHOD("release_glasses", "glasses_id"), &TiltFiveXRInterface::release_glasses);
ClassDB::bind_method(D_METHOD("get_available_glasses_ids"), &TiltFiveXRInterface::get_available_glasses_ids);
Expand Down Expand Up @@ -141,21 +140,21 @@ void TiltFiveXRInterface::start_display(const StringName glasses_id, Variant vob
ERR_FAIL_COND_MSG(!entry, "Glasses id was not found");

auto viewport = Object::cast_to<SubViewport>(vobj);
auto xr_origin = Object::cast_to<XROrigin3D>(oobj);
auto gameboard = Object::cast_to<TiltFiveGameboard>(oobj);
ERR_FAIL_NULL_MSG(viewport, "Parameter 2 is not a SubViewport");
ERR_FAIL_NULL_MSG(xr_origin, "Parameter 3 is not a XROrigin3D");
ERR_FAIL_NULL_MSG(gameboard, "Parameter 3 is not a TiltFiveGameboard");

_start_display(*entry, viewport, xr_origin);
_start_display(*entry, viewport, gameboard);
}

void TiltFiveXRInterface::_start_display(TiltFiveXRInterface::GlassesIndexEntry& entry, SubViewport* viewport, XROrigin3D* xr_origin) {
void TiltFiveXRInterface::_start_display(TiltFiveXRInterface::GlassesIndexEntry& entry, SubViewport* viewport, TiltFiveGameboard* gameboard) {
auto glasses = entry.glasses.lock();
if(!glasses->is_reserved()) {
WARN_PRINT("Glasses need to be reserved to display viewport");
return;
}
entry.viewport_id = viewport->get_instance_id();
entry.xr_origin_id = xr_origin->get_instance_id();
entry.gameboard_id = gameboard->get_instance_id();

viewport->set_use_xr(true);
viewport->set_update_mode(godot::SubViewport::UpdateMode::UPDATE_ALWAYS);
Expand All @@ -175,7 +174,7 @@ void TiltFiveXRInterface::_stop_display(GlassesIndexEntry& entry) {
viewport->set_update_mode(godot::SubViewport::UpdateMode::UPDATE_DISABLED);
}
entry.viewport_id = ObjectID();
entry.xr_origin_id = ObjectID();
entry.gameboard_id = ObjectID();
}

void TiltFiveXRInterface::release_glasses(const StringName glasses_id) {
Expand Down Expand Up @@ -287,6 +286,7 @@ Transform3D TiltFiveXRInterface::_get_transform_for_view(uint32_t view, const Tr
WARN_PRINT_ONCE("Glasses not set");
return Transform3D();
}
// Should be the gameboard scale set in _pre_draw_viewport
auto world_scale = xr_server->get_world_scale();

auto eye_transform = _render_glasses->get_eye_transform(view == 0 ? Eye::Left : Eye::Right);
Expand Down Expand Up @@ -320,12 +320,12 @@ bool TiltFiveXRInterface::_pre_draw_viewport(const RID &render_target) {
if(!_render_glasses->is_reserved())
return false;

auto xr_origin = Object::cast_to<TiltFiveGameboard>(ObjectDB::get_instance(entry->xr_origin_id));
if(!xr_origin)
auto gameboard = Object::cast_to<TiltFiveGameboard>(ObjectDB::get_instance(entry->gameboard_id));
if(!gameboard)
return false;

xr_server->set_world_origin(xr_origin->get_global_transform());
xr_server->set_world_scale(xr_origin->get_gameboard_scale());
xr_server->set_world_origin(gameboard->get_global_transform());
xr_server->set_world_scale(gameboard->get_gameboard_scale());

entry->rendering = true;
return true;
Expand Down
7 changes: 3 additions & 4 deletions extension/src/TiltFiveXRInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

#include <godot_cpp/core/binder_common.hpp>
#include <godot_cpp/classes/xr_server.hpp>
#include <godot_cpp/classes/xr_origin3d.hpp>
#include <godot_cpp/classes/sub_viewport.hpp>
#include <godot_cpp/variant/packed_string_array.hpp>

#include <GodotT5Service.h>
#include <GodotT5Glasses.h>
#include <TiltFiveGameboard.h>

using godot::XRInterfaceExtension;
using godot::XRServer;
Expand All @@ -24,7 +24,6 @@ using godot::RID;
using godot::SubViewport;
using godot::PackedStringArray;
using godot::ObjectID;
using godot::XROrigin3D;
using godot::Variant;
using GodotT5Integration::GodotT5Service;
using GodotT5Integration::GodotT5Glasses;
Expand All @@ -38,7 +37,7 @@ class TiltFiveXRInterface : public XRInterfaceExtension {
int idx;
std::weak_ptr<GodotT5Glasses> glasses;
ObjectID viewport_id;
ObjectID xr_origin_id;
ObjectID gameboard_id;
bool rendering;
};

Expand Down Expand Up @@ -99,7 +98,7 @@ class TiltFiveXRInterface : public XRInterfaceExtension {
protected:
static void _bind_methods();

void _start_display(GlassesIndexEntry& entry, SubViewport* viewport, XROrigin3D* xr_origin);
void _start_display(GlassesIndexEntry& entry, SubViewport* viewport, TiltFiveGameboard* xr_origin);
void _stop_display(GlassesIndexEntry& entry);

GlassesIndexEntry* lookup_glasses_entry(StringName glasses_id);
Expand Down

0 comments on commit e95ef3d

Please sign in to comment.