Skip to content

RH camera fixes #16691

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

Merged
merged 3 commits into from
May 30, 2025
Merged

RH camera fixes #16691

merged 3 commits into from
May 30, 2025

Conversation

bghgary
Copy link
Contributor

@bghgary bghgary commented May 29, 2025

This fixes an issue we have with cameras when in right-handed system where setting rotation or rotationQuaterion on a camera in right-handed system actually sets the camera 180 flipped from what is represented in the view matrix.

You can see this problem using this PG: https://playground.babylonjs.com/#BDQ72M#1
On line 14, we are setting the rotation to 0,0,0, but the rotation from the world matrix of the camera is 0,PI,0.

This change fixes the problem, but it is a breaking change for setting the rotation properties since it will behave 180 flipped from before. The default orientation of camera will still work as before (i.e., always point to +Z for both LH and RH) to maintain backwards compatibility as much as possible.

The fix involves changing the reference point of camera. The code mistakenly uses the same reference point of 0,0,1 for both LH and RH view matrix. Babylon target camera's LH and RH view matrices are flipped by Z. Thus, the reference point should also flip by Z for the math to work.

There is a secondary problem in setTarget where it is hard-coded to use LH math. This has been fixed to consider RH.

@bjsplat
Copy link
Collaborator

bjsplat commented May 29, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented May 29, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bghgary bghgary changed the title WIP: RH camera fixes RH camera fixes May 30, 2025
@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bghgary bghgary requested a review from deltakosh May 30, 2025 17:48
@bghgary bghgary marked this pull request as ready for review May 30, 2025 17:48
@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented May 30, 2025

@deltakosh deltakosh enabled auto-merge (squash) May 30, 2025 21:13
@deltakosh deltakosh merged commit fc791e4 into BabylonJS:master May 30, 2025
18 checks passed
docEdub added a commit to docEdub/Babylon.js that referenced this pull request Aug 5, 2025
This change applies the recent right hand camera fixes from PR BabylonJS#16691 to the WebXR camera.
@docEdub docEdub mentioned this pull request Aug 5, 2025
docEdub added a commit that referenced this pull request Aug 6, 2025
This change applies the recent right hand camera fixes from PR #16691 to
the WebXR camera.

Test playground: https://playground.babylonjs.com/#4EGO4T#3.
VicenteCartas pushed a commit to VicenteCartas/Babylon.js that referenced this pull request Aug 7, 2025
This fixes an issue we have with cameras when in right-handed system
where setting `rotation` or `rotationQuaterion` on a camera in
right-handed system actually sets the camera 180 flipped from what is
represented in the view matrix.

You can see this problem using this PG:
https://playground.babylonjs.com/#BDQ72M#1
On line 14, we are setting the `rotation` to `0,0,0`, but the rotation
from the world matrix of the camera is `0,PI,0`.

This change fixes the problem, but it is a breaking change for setting
the rotation properties since it will behave 180 flipped from before.
The default orientation of camera will still work as before (i.e.,
always point to +Z for both LH and RH) to maintain backwards
compatibility as much as possible.

The fix involves changing the reference point of camera. The code
mistakenly uses the same reference point of `0,0,1` for both LH and RH
view matrix. Babylon target camera's LH and RH view matrices are flipped
by Z. Thus, the reference point should also flip by Z for the math to
work.

There is a secondary problem in `setTarget` where it is hard-coded to
use LH math. This has been fixed to consider RH.
VicenteCartas pushed a commit to VicenteCartas/Babylon.js that referenced this pull request Aug 7, 2025
This change applies the recent right hand camera fixes from PR BabylonJS#16691 to
the WebXR camera.

Test playground: https://playground.babylonjs.com/#4EGO4T#3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants