-
Notifications
You must be signed in to change notification settings - Fork 29
fix viewer rotating on any mouse movement #48
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
base: main
Are you sure you want to change the base?
Conversation
on firefox, regardless of whether mouse left click is pressed, the viewer would follow the mouse's movement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where the 3D viewer was incorrectly rotating on any mouse movement in Firefox, regardless of whether the left mouse button was pressed. The fix ensures that rotation only occurs when the mouse button is actually being held down.
- Fixed mouse rotation logic to check for mouse button state before applying rotation
- Added proper mouse button state validation in the rotation calculation
@@ -169,7 +169,7 @@ class AppController { | |||
// desktop rotate | |||
v.set(0, 0, 0); | |||
const mouseRotate = new Vec3(mouse[0], mouse[1], 0); | |||
v.add(mouseRotate.mulScalar((1 - this._mouse[2]) * this.orbitSpeed * dt)); | |||
v.add(mouseRotate.mulScalar(this._mouse[0] * (1 - this._mouse[2]) * this.orbitSpeed * dt)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix incorrectly multiplies by this._mouse[0] (X position) instead of checking mouse button state. This will scale rotation by the X coordinate rather than enabling/disabling it based on button press. Consider using a boolean mouse button state or the appropriate mouse button index.
v.add(mouseRotate.mulScalar(this._mouse[0] * (1 - this._mouse[2]) * this.orbitSpeed * dt)); | |
if (this._mouseButtonPressed) { // Check if the mouse button is pressed | |
v.add(mouseRotate.mulScalar((1 - this._mouse[2]) * this.orbitSpeed * dt)); | |
} |
Copilot uses AI. Check for mistakes.
@izeng0975 when you say regardless if mouse left click is pressed what do you mean? Any of the mouse buttons to allow for rotation or pointer lock? Im not quite sure what you are trying to achieve here |
sorry for the bad wording, its hard to explain with words so I made two YouTube videos to show the difference before and after. This is the bug (specifically on Firefox doesn't happen in Chrome, Safari, or Brave) https://youtu.be/9MWu299un2k usually while holding left click, you can move your mouse around and the camera will follow. However, on Firefox, even after releasing left click, the camera seems to follow the mouse cursor and movement. The fix I implemented shown here https://www.youtube.com/watch?v=xNC6qkkymJE shows the results of changing the line of code to make the behavior proper for Firefox again |
on firefox, regardless of whether mouse left click is pressed, the viewer would follow the mouse's movement