Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make proper use of WaitGetPoses #141

Open
wants to merge 1 commit into
base: Godot-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions demo/Main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=27 format=2]
[gd_scene load_steps=28 format=2]

[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://assets/wahooney.itch.io/green_grid.tres" type="Material" id=2]
Expand All @@ -23,6 +23,7 @@
[ext_resource path="res://addons/godot-openvr/scenes/ovr_right_hand.tscn" type="PackedScene" id=21]
[ext_resource path="res://addons/godot-openvr/scenes/ovr_shader_cache.tscn" type="PackedScene" id=22]
[ext_resource path="res://misc/Cup.tscn" type="PackedScene" id=23]
[ext_resource path="res://addons/godot-openvr/scenes/framecounter_in_3d.tscn" type="PackedScene" id=24]

[sub_resource type="ArrayMesh" id=1]

Expand All @@ -46,14 +47,17 @@ directional_shadow_max_distance = 50.0

[node name="Player" type="ARVROrigin" parent="."]
script = ExtResource( 13 )
action_json_path = "res://ovr_actions/actions.json"

[node name="ARVRCamera" type="ARVRCamera" parent="Player"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8, 0 )

[node name="vr_common_shader_cache" parent="Player/ARVRCamera" instance=ExtResource( 3 )]

[node name="ovr_shader_cache" parent="Player/ARVRCamera" instance=ExtResource( 22 )]

[node name="FPS" parent="Player/ARVRCamera" instance=ExtResource( 24 )]
transform = Transform( 0.923552, -0.383473, 0, -0.0754683, -0.181757, -0.980443, 0.375974, 0.90549, -0.196802, 0.331706, 0.188307, -0.889295 )

[node name="Left_Hand" parent="Player" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.5, 1.25, 0 )

Expand Down Expand Up @@ -82,7 +86,6 @@ canFly = false
transform = Transform( 0.707107, 2.98023e-08, -0.707107, 0.5, 0.707107, 0.5, 0.5, -0.707107, 0.5, 0.15, 0.1, 0 )
screen_size = Vector2( 0.2, 0.2 )
viewport_size = Vector2( 200, 200 )
transparent = true
scene = ExtResource( 11 )
collision_layer = 0

Expand Down Expand Up @@ -156,5 +159,6 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 2, -4 )

[node name="Box03" parent="Misc" instance=ExtResource( 8 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -3, 3, -4 )

[connection signal="action_pressed" from="Player/Right_Hand" to="." method="_on_Right_Hand_action_pressed"]
[connection signal="pressed" from="Player/Guardian/Toggle" to="." method="_on_Toggle_Guardian_pressed"]
2 changes: 1 addition & 1 deletion demo/addons/godot-openvr/scenes/framecounter_in_3d.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void vertex() {
}

void fragment() {
vec4 col = texture(viewport_texture, vec2(1.0 - UV.x, UV.y));
vec4 col = texture(viewport_texture, vec2(UV.x, 1.0 - UV.y));
ALBEDO = col.rgb;
ALPHA = col.a;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ARVRInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ godot_transform godot_arvr_get_transform_for_eye(void *p_data, godot_int p_eye,
godot_real world_scale = godot::arvr_api->godot_arvr_get_worldscale();

if (p_eye == 0) {
// we want a monoscopic transform.. shouldn't really apply here
// we want a monoscopic transform.. used when updating our camera node position (in this case we'll be using next frames position)
godot::api->godot_transform_new_identity(&transform_for_eye);
} else if (arvr_data->ovr != NULL) {
arvr_data->ovr->get_eye_to_head_transform(&transform_for_eye, p_eye, world_scale);
Expand All @@ -158,7 +158,7 @@ godot_transform godot_arvr_get_transform_for_eye(void *p_data, godot_int p_eye,
// :)
ret = *p_cam_transform;
ret = godot::api->godot_transform_operator_multiply(&ret, &reference_frame);
ret = godot::api->godot_transform_operator_multiply(&ret, arvr_data->ovr->get_hmd_transform());
ret = godot::api->godot_transform_operator_multiply(&ret, arvr_data->ovr->get_hmd_transform(p_eye == 0));
ret = godot::api->godot_transform_operator_multiply(&ret, &transform_for_eye);

return ret;
Expand Down
22 changes: 17 additions & 5 deletions src/open_vr/openvr_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ void openvr_data::process() {

// update our poses structure, this tracks our controllers
vr::TrackedDevicePose_t tracked_device_pose[vr::k_unMaxTrackedDeviceCount];
vr::TrackedDevicePose_t tracked_device_next_pose[vr::k_unMaxTrackedDeviceCount];

if (get_application_type() == openvr_data::OpenVRApplicationType::OVERLAY) {
openvr_data::OpenVRTrackingUniverse tracking_universe = get_tracking_universe();
Expand All @@ -360,8 +361,11 @@ void openvr_data::process() {
} else {
vr::VRSystem()->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseRawAndUncalibrated, 0.0, tracked_device_pose, vr::k_unMaxTrackedDeviceCount);
}
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) {
tracked_device_next_pose[i] = tracked_device_pose[i];
}
} else {
vr::VRCompositor()->WaitGetPoses(tracked_device_pose, vr::k_unMaxTrackedDeviceCount, NULL, 0);
vr::VRCompositor()->WaitGetPoses(tracked_device_pose, vr::k_unMaxTrackedDeviceCount, tracked_device_next_pose, vr::k_unMaxTrackedDeviceCount);
}

// update trackers and joysticks
Expand All @@ -372,13 +376,17 @@ void openvr_data::process() {
// store our HMD transform
transform_from_matrix(&hmd_transform, &tracked_device_pose[i].mDeviceToAbsoluteTracking, world_scale);
}
if (tracked_device_next_pose[i].bPoseIsValid) {
// store our HMD transform
transform_from_matrix(&hmd_transform_next, &tracked_device_next_pose[i].mDeviceToAbsoluteTracking, world_scale);
}
} else if (tracked_devices[i].tracker_id != 0) {
// We'll keep using our main transform we got from WaitGetPoses
// To obtain specific poses use OpenVRPose
if (tracked_device_pose[i].bPoseIsValid) {
if (tracked_device_next_pose[i].bPoseIsValid) {
// update our location and orientation
godot_transform transform;
transform_from_matrix(&transform, &tracked_device_pose[i].mDeviceToAbsoluteTracking, 1.0);
transform_from_matrix(&transform, &tracked_device_next_pose[i].mDeviceToAbsoluteTracking, 1.0);
godot::arvr_api->godot_arvr_set_controller_transform(tracked_devices[i].tracker_id, &transform, true, true);
}

Expand Down Expand Up @@ -981,8 +989,12 @@ void openvr_data::set_default_action_set(const String p_name) {
}
}

const godot_transform *openvr_data::get_hmd_transform() const {
return &hmd_transform;
const godot_transform *openvr_data::get_hmd_transform(bool p_next_frame) const {
if (p_next_frame) {
return &hmd_transform_next;
} else {
return &hmd_transform;
}
}

////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/open_vr/openvr_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class openvr_data {
void process_device_actions(tracked_device *p_device, uint64_t p_msec);

godot_transform hmd_transform;
godot_transform hmd_transform_next;

// custom actions
struct custom_action {
Expand Down Expand Up @@ -190,7 +191,7 @@ class openvr_data {
// interact with tracking info
godot::String get_default_action_set() const;
void set_default_action_set(const godot::String p_name);
const godot_transform *get_hmd_transform() const;
const godot_transform *get_hmd_transform(bool p_next_frame = false) const;
int register_action_set(const godot::String p_action_set);
void set_active_action_set(const godot::String p_action_set);
void toggle_action_set_active(const godot::String p_action_set, bool p_is_active);
Expand Down