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

p5.Camera.slerp() behaves strangely #6508

Closed
1 of 17 tasks
inaridarkfox4231 opened this issue Oct 29, 2023 · 0 comments · Fixed by #6509
Closed
1 of 17 tasks

p5.Camera.slerp() behaves strangely #6508

inaridarkfox4231 opened this issue Oct 29, 2023 · 0 comments · Fixed by #6509

Comments

@inaridarkfox4231
Copy link
Contributor

inaridarkfox4231 commented Oct 29, 2023

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

p5.js version

1.8.0

Web browser and version

Chrome

Operating System

Windows11

Steps to reproduce this

Steps:

  1. Performing a reset on the p5.Camera.slerp() demo page
  2. The camera behaves strangely while trying to return to its original position.

Snippet:

SLERP_BUG

let mycam, lastCam, initialCam;
let countForReset = 30;
// This sample uses orbitControl() to move the camera.
// Double-clicking the canvas restores the camera to its initial state.
function setup() {
  createCanvas(400, 400, WEBGL);
  strokeWeight(3);

  mycam = createCamera(); // main camera
  lastCam = createCamera(); // Camera for recording loc info before reset
  initialCam = createCamera(); // Camera for recording the initial state

  setCamera(mycam); // set main camera
}

function draw() {
  if (countForReset < 30) {
    // if the reset count is less than 30,
    // it will move closer to the original camera as it increases.
    countForReset++;
    mycam.slerp(lastCam, initialCam, countForReset / 30);
  } else {
    // if the count is 30,
    // you can freely move the main camera with orbitControl().
    orbitControl();
  }

  background(255);
  box(160);
}
// A double-click sets countForReset to 0 and initiates a reset.
function doubleClicked() {
  if (countForReset === 30) {
    countForReset = 0;
    lastCam.set(mycam);
  }
}
2023-10-29.22-00-05.mp4

In addition, we have confirmed that slerp behaves strangely in some sketches.

I know the cause.
#6287
This is because the specifications of row() and column() were changed in this commit, calling it a bug.
I was the one who created this specification, but from the perspective of looking at the elements of a matrix from left to right, this is not a bug.

However,

It no longer matters what is a bug or what is not. I'm tired of repeating pointless discussions about it.
I have no connection with the circumstances or validity of this specification change, and I have no interest in it.
This problem has already been resolved, so I'll just state my conclusion, and create a pull request, and solve it. That's it.

CAMERA_SLERP_BUG

  // BUG IS HERE.

  var front0 = rotMat0.column(2);
  var front1 = rotMat1.column(2);
  var up0 = rotMat0.column(1);
  var up1 = rotMat1.column(1);
  // FIX THE BUG


  // The specifications of column() and row() have been reversed, so column() must be rewritten as row().
  var front0 = rotMat0.row(2);
  var front1 = rotMat1.row(2);
  var up0 = rotMat0.row(1);
  var up1 = rotMat1.row(1); // prepare new vectors.
2023-10-29.22-10-43.mp4

That's all.
It may affect unit tests, but since this behavior is correct, it makes sense to adapt to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant