Skip to content

Commit

Permalink
Tidied comments. Reinstated root tracker's position.
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Cyber-Captain committed Nov 4, 2024
1 parent 13660e2 commit 3d12f8b
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,29 +307,28 @@ void OpenXRFbBodyTrackingExtensionWrapper::_on_process() {
// If the location data is good then we need to apply some corrections
// before handing the data back to Godot. These include:
//
// - The Root joint carries no data, so instead place it on the ground
// - The Root joint carries no useful orientation data, so instead align it
// under the hips pointing forwards.
//
// - Adjusting the left and right shoulder back so they are aligned
// with how models are designed, rather than the Meta positions of
// the tips of the clavicles.
if (locations.isActive) {
// Construct a root under the hips pointing forwards
// IE, +z aligns with hips & user's real-world forward.
// (Remaining, however, on the XRorigin / Global XZ plane; root's basis rotated around Y to fit)
// Align root under the hips pointing 'forwards'
// IE, +z aligns with hips & user's real-world [upper-body] forward.
// (Remaining, however, parallel to the XRorigin / Global XZ plane; root's basis rotated around Y to fit)

// Get the hips transform
Transform3D hips = xr_body_tracker->get_joint_transform(XRBodyTracker::JOINT_HIPS);
Vector3 root_y = Vector3(0.0, 1.0, 0.0);
Vector3 hips_left = hips.basis.get_column(Vector3::AXIS_X);
// flatten hips' left (x basis) on to real-world / global ground plane. Normalize.
Vector3 root_x = (hips_left.slide(Vector3(0.0, 1.0, 0.0))).normalized();
Vector3 root_z = root_x.cross(root_y);
// flatten hips' origin on to ground plane.
Vector3 root_o = hips.origin.slide(Vector3(0.0, 1.0, 0.0));
// set the actual root transform
Vector3 root_o = xr_body_tracker->get_joint_transform(XRBodyTracker::JOINT_ROOT).origin;
Transform3D root = Transform3D(root_x, root_y, root_z, root_o).orthonormalized();
xr_body_tracker->set_joint_transform(XRBodyTracker::JOINT_ROOT, root);
// Set tracker pose, velocities, confidence.
xr_body_tracker->set_pose("default", root, Vector3(), Vector3(), XRPose::XR_TRACKING_CONFIDENCE_HIGH);

// Distance in meters to push the shoulder joints back from the
// clavicle-position to be in-line with the upper arm joints as
Expand All @@ -350,9 +349,6 @@ void OpenXRFbBodyTrackingExtensionWrapper::_on_process() {
right_shoulder.origin += shoulder_offset;
xr_body_tracker->set_joint_transform(XRBodyTracker::JOINT_RIGHT_SHOULDER, right_shoulder);

// Set tracker pose, velocities, confidence.
// Good to go.
xr_body_tracker->set_pose("default", root, Vector3(), Vector3(), XRPose::XR_TRACKING_CONFIDENCE_HIGH);
}

// Register the XRBodyTracker if necessary
Expand Down

0 comments on commit 3d12f8b

Please sign in to comment.