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

Fix rotation properties being in degrees irrespective of angleMode #6589

Merged
merged 6 commits into from
Jan 21, 2024

Conversation

SlightlyEpic
Copy link
Contributor

Resolves #6565

Changes:

  1. Fixing the incorrectly lowercased reference to constants.RADIANS at

    if (this._angleMode === constants.radians) {

    This was also casuing rotation and pRotation properties being in degrees irrespective of the _angleMode.

  2. Changes to _handleMotion function were made to make it work with both degree and radian values.

  3. Changes in unit tests related to rotation were made as they expected degree values despite the default mode being radian.

  4. The angleMode method in math/trigonometry.js was also changed to update pRotation properties when the mode is changed, this is needed because otherwise the units of rotation and pRotation could end up different, which may cause the deviceTurned event to fire incorrectly.

PR Checklist

  • npm run lint passes
  • [Inline documentation] is included / updated
  • [Unit tests] are included / updated

@SlightlyEpic SlightlyEpic changed the title Rad Fix rotation properties being in degrees irrespective of angleMode Nov 25, 2023
Comment on lines 622 to 629

let multiplier = 1;
if (this._angleMode === constants.RADIANS) {
multiplier = constants.PI / 180.0;
}
this._setProperty('rotationX', e.beta);
this._setProperty('rotationY', e.gamma);
this._setProperty('rotationZ', e.alpha);
this._setProperty('rotationX', e.beta * multiplier);
this._setProperty('rotationY', e.gamma * multiplier);
this._setProperty('rotationZ', e.alpha * multiplier);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an internal method to convert angles, can you see if you can use that to simplify the implementation instead? https://github.com/processing/p5.js/blob/main/src/math/trigonometry.js#L437

@SlightlyEpic
Copy link
Contributor Author

Ive added a new internal method, similar to the one you pointed out which converts from degrees to the current angle mode unit (since that one was missing and was needed here).
Another simplification i made is that in the _handleMotion method, instead of switching the equations based on angle mode, rotation properties are now converted into degrees beforehand and all calculations are done in degrees.

@limzykenneth limzykenneth merged commit 2a766a5 into processing:main Jan 21, 2024
2 checks passed
@limzykenneth
Copy link
Member

Looks good. Thanks!

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

Successfully merging this pull request may close these issues.

Multiple reference to non-existant constant POLYGON in Renderer2D
2 participants