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

Overlay flipping when directly above #183

Open
meir opened this issue Mar 18, 2025 · 2 comments
Open

Overlay flipping when directly above #183

meir opened this issue Mar 18, 2025 · 2 comments

Comments

@meir
Copy link

meir commented Mar 18, 2025

When laying down in VR, putting a window above your head flips it around when passing behind your headset on a vertical axis. As if the location of the overlay is based on a cylinder with the ends stitched.

Ideally the overlay would stay in orientation of your view and not based on location.

@galister
Copy link
Owner

galister commented Mar 19, 2025

this is because of the realign function (which sets the overlay rotation upon/after grab). this uses a manual implementation of look_at_rh, which is bound to the global up vector.

would need to come up with a way that handles well in both mostly-upright cases (overlay needs to snap to horizon), but also doesn't break at extremities like what you've mentioned.

this is the part, if you want to try your hand at it:

let dot = to_hmd.normalize().dot(hmd.z_axis);
let z_dist = to_hmd.length();
let y_dist = (self.transform.translation.y - hmd.translation.y).abs();
let x_angle = (y_dist / z_dist).asin();
if dot < -f32::EPSILON {
// facing down
let up_point = hmd.translation + z_dist / x_angle.cos() * Vec3A::Y;
up_dir = (up_point - self.transform.translation).normalize();
} else if dot > f32::EPSILON {
// facing up
let dn_point = hmd.translation + z_dist / x_angle.cos() * Vec3A::NEG_Y;
up_dir = (self.transform.translation - dn_point).normalize();
} else {
// perfectly upright
up_dir = Vec3A::Y;

@meir
Copy link
Author

meir commented Mar 19, 2025

yes thank you, that helps quite a bit, i'll look at it later this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants