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 camera tilt function to prevent orientation flipping #7598

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Forchapeatl
Copy link
Contributor

@Forchapeatl Forchapeatl commented Mar 4, 2025

Resolves #7377

Changes:

  • Fixed an issue where p5.Camera.tilt() did not update the up vector.
  • Prevents rapid orientation flipping when tilting too far.
  • Ensures the up vector remains perpendicular by recalculating it dynamically.

Screenshots of the change:

PR Checklist

@Forchapeatl Forchapeatl changed the base branch from main to dev-2.0 March 4, 2025 12:13
@Forchapeatl Forchapeatl closed this Mar 4, 2025
@Forchapeatl Forchapeatl reopened this Mar 4, 2025
@Forchapeatl Forchapeatl changed the base branch from dev-2.0 to main March 4, 2025 12:23
Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on, I think your approach looks good! Two things before merging:

  • Since the pan/tilt/etc functions have been a tad buggy in the past, do you think we can add a unit test to check the result of the up vector after a tilt?
  • Like your other recent PR, I assume this applies to p5 2.0 as well. Once this one is ready, could you also make a second PR into the dev-2.0 branch?

@@ -2448,17 +2448,33 @@ p5.Camera = class Camera {
rotatedCenter[1] += this.eyeY;
rotatedCenter[2] += this.eyeZ;

// Compute new up vector to prevent flipping
let forward = createVector(
Copy link
Contributor

Choose a reason for hiding this comment

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

The global createVector function isn't available in instance mode, can we import the vector class directly and do new Vector(...) here instead?

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.

p5.Camera.tilt() does not update the up vector leading to rapid orientation flipping
2 participants