Skip to content

Commit

Permalink
Merge pull request #6509 from inaridarkfox4231/fix_slerpBUG
Browse files Browse the repository at this point in the history
fix camera slerp() BUG
  • Loading branch information
davepagurek committed Oct 30, 2023
2 parents 611941a + cf0c5f4 commit e40c8e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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]);
});
});
});
});

0 comments on commit e40c8e0

Please sign in to comment.