Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Fixing worldscale for controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
BastiaanOlij committed May 19, 2020
1 parent a76540e commit 39a3c01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var ovr_vr_api_proxy = null;
# some of the Oculus VrAPI constants are defined in this file. Have a look into it to learn more
var ovrVrApiTypes = load("res://addons/godot_ovrmobile/OvrVrApiTypes.gd").new();

# react to the worldscale changing
var was_world_scale = 1.0

func _ready():
_initialize_ovr_mobile_arvr_interface();
Expand All @@ -35,6 +37,7 @@ func _ready():
func _process(delta_t):
_check_and_perform_runtime_config()
_check_move(delta_t)
_check_worldscale()


# this code check for the OVRMobile inteface; and if successful also initializes the
Expand Down Expand Up @@ -234,3 +237,11 @@ func _on_RightTouchController_button_release(button):
if (ovr_utilities):
# reset the color to neutral again
ovr_utilities.set_default_layer_color_scale(Color(1.0, 1.0, 1.0, 1.0));

func _check_worldscale():
if was_world_scale != world_scale:
was_world_scale = world_scale
var inv_world_scale = 1.0 / was_world_scale
var controller_scale = Vector3(inv_world_scale, inv_world_scale, inv_world_scale)
$"LeftTouchController/left-controller".scale = controller_scale
$"RightTouchController/right-controller".scale = controller_scale
8 changes: 4 additions & 4 deletions plugin/src/main/cpp/ovr_mobile_controller.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created by Fredia Huya-Kouadio.
* Created by Fredia Huya-Kouadio.
*/

#include "ovr_mobile_controller.h"
Expand Down Expand Up @@ -191,7 +191,7 @@ void OvrMobileController::update_controller_tracking_state_tracked_remote(ovrMob

// Update the controller transform.
godot_transform transform;
godot_transform_from_ovr_pose(&transform, controller_state.tracking_state.HeadPose.Pose, godot::arvr_api->godot_arvr_get_worldscale());
godot_transform_from_ovr_pose(&transform, controller_state.tracking_state.HeadPose.Pose, 1.0); // worldscale is already applied in godot_arvr_set_controller_transform
godot::arvr_api->godot_arvr_set_controller_transform(controller_state.godot_controller_id, &transform,
has_orientation_tracking(controller_state.remote_capabilities),
has_position_tracking(controller_state.remote_capabilities));
Expand All @@ -208,7 +208,7 @@ void OvrMobileController::update_controller_tracking_state_hand(ovrMobile *ovr,
// Update the controller transform.
godot_transform transform;
//godot_transform_from_ovr_pose(&transform, controller_state.tracking_state.HeadPose.Pose, godot::arvr_api->godot_arvr_get_worldscale());
godot_transform_from_ovr_pose(&transform, controller_state.hand_pose.RootPose, godot::arvr_api->godot_arvr_get_worldscale());
godot_transform_from_ovr_pose(&transform, controller_state.hand_pose.RootPose, 1.0); // worldscale is already applied in godot_arvr_set_controller_transform
godot::arvr_api->godot_arvr_set_controller_transform(controller_state.godot_controller_id, &transform, true, true);
}

Expand Down Expand Up @@ -257,7 +257,7 @@ void OvrMobileController::update_controllers_connection_state(ovrMobile *ovr, ov
}

ControllerHand handedness = get_controller_handedness(tracked_hand_capabilities);

// this check forces a reconnect below because the type of the controller changed
if (controllers[handedness].capability_header.Type != ovrControllerType_Hand && controllers[handedness].godot_controller_id != kInvalidGodotControllerId) {
godot::arvr_api->godot_arvr_remove_controller(controllers[handedness].godot_controller_id);
Expand Down

0 comments on commit 39a3c01

Please sign in to comment.