diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 2a9d42eb18..3d20076e2d 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -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(); diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index 1c8fb7214b..0704a64728 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -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() { @@ -1072,4 +1087,4 @@ suite('p5.Camera', function() { assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); }); }); -}); \ No newline at end of file +});