TransformControls: Use in-plane rotation when eye and selected gizmo axis are parallel #26860
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I found this bug when using the rotate TransformControls in a web-app that allows users to set a camera to be perfectly parallel to a cardinal axis. When the TransformControls eye and the selected axis for rotation are parallel, the resulting rotation is zero as the cross product of two parallel vectors is the zero vector and the dot product with the zero vector is zero. This was fixed by performing the cross product and checking if the resulting vector has a length of zero, indicating that the vectors are parallel. If the vectors are parallel, the rotation logic for the
E
handle is used.This bug does not occur very often as setting the value of
this.eye
from the camera position usually small rounding errors causing the vector to not be perfectly parallel with a cardinal axis. For the app I am working on, the camera can be set perfectly inline with a cardinal axis when the rotation control is displayed causing the bug to occur frequently.Other notes/questions:
_inPlaneRotation
is the best name for the variable. I tend to refer to theE
handle as the in-plane handle but I am open to other suggestions._tempVector
is equal to_zeroVector
as the resulting vector could include-0
and may not be strictly equal to_zeroVector
even when_tempVector
andthis.eye
are parallelBefore (using a modified version of the transform controls example where I have hardcoded the camera position to be parallel to the x-axis):
Screen.Recording.2023-09-27.at.4.52.49.PM.mov
After:
Screen.Recording.2023-09-27.at.4.53.17.PM.mov