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 slerp() BUG #6509

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/webgl/p5.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1818,10 +1818,10 @@ p5.Camera = class Camera {
const rotMat1 = cam1.cameraMatrix.createSubMatrix3x3();

// get front and up vector from local-coordinate-system.
const front0 = rotMat0.column(2);
const front1 = rotMat1.column(2);
const up0 = rotMat0.column(1);
const up1 = rotMat1.column(1);
const front0 = rotMat0.row(2);
const front1 = rotMat1.row(2);
const up0 = rotMat0.row(1);
const up1 = rotMat1.row(1);

// prepare new vectors.
const newFront = new p5.Vector();
Expand Down
17 changes: 16 additions & 1 deletion test/unit/webgl/p5.Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,21 @@ suite('p5.Camera', function() {
expect(myCam.projMatrix.mat4[5])
.to.be.closeTo(p0_5 * Math.pow(p1_5 / p0_5, 0.3), 0.00001);
});
test('Preventing bugs from occurring by changes in slerp spec', function() {
myCam = myp5.createCamera();
const cam0 = myp5.createCamera();
const cam1 = myp5.createCamera();
cam0.camera(100, 763, 1073, 100, 480, 380, 0, 1, 2);
cam1.camera(300, 400, 700, 0, 0, 0, 2, 3, 1);
myCam.slerp(cam0, cam1, 0.1);
const expectedSlerpedMatrix = new Float32Array([
0.9983342289924622, 0.04771510139107704, 0.03243450075387955, 0,
-0.056675542145967484, 0.9162729382514954, 0.39652466773986816, 0,
-0.010798640549182892, -0.3977023959159851, 0.9174509048461914, 0,
-66.60199737548828, -260.3179016113281, -1242.9371337890625, 1
]);
assert.deepEqual(myCam.cameraMatrix.mat4, expectedSlerpedMatrix);
});
});

suite('Helper Functions', function() {
Expand Down Expand Up @@ -1072,4 +1087,4 @@ suite('p5.Camera', function() {
assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]);
});
});
});
});