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

Do not use angleBetween() for angle calculation in _orbit() inside orbtiControl(). #6154

Merged
merged 2 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/webgl/p5.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1746,7 +1746,11 @@ p5.Camera.prototype._orbit = function(dTheta, dPhi, dRadius) {

// calculate updated camera angle
// Find the angle between the "up" and the "front", add dPhi to that.
const camPhi = front.angleBetween(up) + dPhi;
// angleBetween() may return negative value. Since this specification is subject to change
// due to version updates, it cannot be adopted, so here we calculate using a method
// that directly obtains the absolute value.
const camPhi =
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, can we add a comment explaining what this does differently from angleBetween for context for future readers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"Since the specifications of angleBetween() are subject to change due to version updates, a calculation method that directly obtains the angle between two vectors is used here."
How about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I mention the possibility of getting negative numbers?
"angleBetween() can return negative numbers. Since this specification is subject to change due to version updates, it cannot be adopted, so here we calculate using a method that directly obtains the absolute value."
Is this better?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think mentioning negative numbers is good, since that's main motivation and the bit that would cause a bug (and using a separate implementation instead of abs() just makes it a bit more efficient and less likely to break in the future.) Your text looks good!

Math.acos(Math.max(-1, Math.min(1, p5.Vector.dot(front, up)))) + dPhi;
// Rotate by dTheta in the shortest direction from "vertical" to "side"
const camTheta = dTheta;

Expand Down