I upgraded my dependencies recently and came accross this breaking change which makes right handed target cameras rotation flipped on the Y axis when using a right handed system:
This creates 2 issues for my setup of a camera parented to a TransformNode:
Camera rotation with mouse is inverted on the Y axis => I fixed it by inverting the camera quaternion x component
Camera is not pointing in the same direction as its parent
For the second issue, I made the following PG. The idea is to transfer the rotation quaternion of the camera to its parent every frame to ensure the transform and camera forward direction are aligned. It works in left handed, but in right handed, the camera forward is the opposite of the transform forward
Any idea what I could be missing to flip it around?
I have tried adding an additional PI around the Y axis to turn it around, but it did not work:
This is a bug. I have a PR out to fix it, but I need to test it a bunch and maybe add some tests before it can be merged.
This one is trickier. In RH, the camera at identity rotation faces -Z. In order to make everything work, we have to move all the objects to the other side of Z. In addition, the transform node’s lookAt function assumes +Z is forward. We can maybe add a parameter for this, but for now, it needs to be updated by hand to match what an RH camera would do. Here is a PG with the bug fix from the PR that works in both LH and RH: https://playground.babylonjs.com/?snapshot=refs/pull/16849/merge#6XB1RH#12. Let me know if you have any questions.
I also want to point out that transferring rotations from a child to parent will cumulate errors in the long run due to floating point imprecision. If the goal is to put the camera rotation on a transform node instead of the camera itself, it might be better to introduce custom camera input code.
Thanks for investigating! So the transform lookAt working in RH in previous versions was a bug if I understand correctly?
I don’t mind the additional quaternion multiplication, it works for me
As the transform has a reference to the scene, it can get the scene handedness without the need for an additional parameter maybe
My goal is to have a camera that can move with 6 degrees of freedom while retaining the nice controls of the BJS camera so I ended up with this ^^ If you know a better way of implementing this kind of movement I am interested
I find it a bit weird that in RH, lookAt does not “look at” the given position and instead “looks away” Maybe we could have a lookAtRightHanded function instead that works for RH?
I was just thinking out loud, let me know if you change something
As you can see in your PG, rotating the up vector does not update the rotation axis of the camera for mouse inputs, which is another reason why I use the parent transform:
It doesn’t look away, it changes the node such that +Z points at the target in both LH and RH. It appears to look away for this scenario this because the camera faces -Z. It’s a conventions issue. I agree it’s not super consistent though.
I see. We can maybe alter the camera input math in core with a flag or use custom inputs.
Probably yes, but that seems like a lot of effort for a use case that is not often used, hence using a parent transform to take care of this complexity