From a6e2ad43df2f04c7a14cb3f47d31c0676937ece2 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Fri, 16 Jun 2023 16:37:54 -0400 Subject: [PATCH 01/28] created fix for camera settings getting reset each time resizeCanvas() is called --- src/core/rendering.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/rendering.js b/src/core/rendering.js index 6c2cc167fd..34f7d62860 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -156,6 +156,10 @@ p5.prototype.createCanvas = function(w, h, renderer) { p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { + // save camera matrices + const camMat = new Float32Array(this._renderer._curCamera.cameraMatrix.mat4); + const projMat = new Float32Array(this._renderer._curCamera.projMatrix.mat4); + // save canvas properties const props = {}; for (const key in this.drawingContext) { @@ -175,10 +179,19 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { // ignore read-only property errors } } + + // reapply camera matrices + this._renderer._curCamera.cameraMatrix.mat4 = camMat; + if (this._renderer._curCamera.cameraType === "custom") { + this._renderer._curCamera.projMatrix.mat4 = projMat; + this._renderer.uPMatrix.mat4 = projMat; + } + if (!noRedraw) { this.redraw(); } } + //accessible Outputs if (this._addAccsOutput()) { this._updateAccsOutput(); From 786934acfd105fa9eb51991852d7dc6c2c8ee6c4 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Fri, 16 Jun 2023 17:34:37 -0400 Subject: [PATCH 02/28] linting issue fix for cam-fix --- src/core/rendering.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 34f7d62860..43e71ac16d 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -157,9 +157,10 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { // save camera matrices - const camMat = new Float32Array(this._renderer._curCamera.cameraMatrix.mat4); - const projMat = new Float32Array(this._renderer._curCamera.projMatrix.mat4); - + const camMat = + new Float32Array(this._renderer._curCamera.cameraMatrix.mat4); + const projMat = + new Float32Array(this._renderer._curCamera.projMatrix.mat4); // save canvas properties const props = {}; for (const key in this.drawingContext) { @@ -179,19 +180,16 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { // ignore read-only property errors } } - // reapply camera matrices this._renderer._curCamera.cameraMatrix.mat4 = camMat; - if (this._renderer._curCamera.cameraType === "custom") { + if (this._renderer._curCamera.cameraType === 'custom') { this._renderer._curCamera.projMatrix.mat4 = projMat; this._renderer.uPMatrix.mat4 = projMat; } - if (!noRedraw) { this.redraw(); } } - //accessible Outputs if (this._addAccsOutput()) { this._updateAccsOutput(); From 6fdde8c5529a464fc9fbb80d1b1366a939229485 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Fri, 16 Jun 2023 17:52:33 -0400 Subject: [PATCH 03/28] fixed the trailing whitespace problem for cam-fix commit --- src/core/rendering.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 43e71ac16d..3938b10a6f 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -157,9 +157,9 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { // save camera matrices - const camMat = + const camMat = new Float32Array(this._renderer._curCamera.cameraMatrix.mat4); - const projMat = + const projMat = new Float32Array(this._renderer._curCamera.projMatrix.mat4); // save canvas properties const props = {}; From 56af4e126ec0f0d56b5ac70bb4530dbc6f2ad9ed Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Fri, 16 Jun 2023 23:58:28 -0400 Subject: [PATCH 04/28] made it so that it copies the whole camera --- src/core/rendering.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 3938b10a6f..77a91d7ece 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -156,11 +156,9 @@ p5.prototype.createCanvas = function(w, h, renderer) { p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { - // save camera matrices - const camMat = - new Float32Array(this._renderer._curCamera.cameraMatrix.mat4); - const projMat = - new Float32Array(this._renderer._curCamera.projMatrix.mat4); + // copy camera + const cam = + this._renderer._curCamera.copy(); // save canvas properties const props = {}; for (const key in this.drawingContext) { @@ -181,10 +179,11 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { } } // reapply camera matrices - this._renderer._curCamera.cameraMatrix.mat4 = camMat; - if (this._renderer._curCamera.cameraType === 'custom') { - this._renderer._curCamera.projMatrix.mat4 = projMat; - this._renderer.uPMatrix.mat4 = projMat; + this._renderer._curCamera = cam; + if (this._renderer._curCamera.cameraType + === 'custom') { + this._renderer.uPMatrix = + this._renderer._curCamera.projMatrix; } if (!noRedraw) { this.redraw(); From 7c70e77facfe1885f1d5eee0487512ff7cb3a69e Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Sat, 17 Jun 2023 00:00:23 -0400 Subject: [PATCH 05/28] fixed typo --- src/core/rendering.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 77a91d7ece..83d40d4020 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -178,7 +178,7 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { // ignore read-only property errors } } - // reapply camera matrices + // reapply camera this._renderer._curCamera = cam; if (this._renderer._curCamera.cameraType === 'custom') { From 351bde77fe49dcd634d6799b511761481cb30097 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Sat, 17 Jun 2023 09:05:11 -0400 Subject: [PATCH 06/28] flipped equal system regarding custom type projection matrix updating --- src/core/rendering.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 83d40d4020..5ffe9063c7 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -181,7 +181,7 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { // reapply camera this._renderer._curCamera = cam; if (this._renderer._curCamera.cameraType - === 'custom') { + !== 'custom') { this._renderer.uPMatrix = this._renderer._curCamera.projMatrix; } From c41e7696c8ba8c7ec73afe592c65da1813388bd7 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Sat, 17 Jun 2023 09:08:38 -0400 Subject: [PATCH 07/28] wait no that wasn't a typo sorry about that --- src/core/rendering.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 5ffe9063c7..83d40d4020 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -181,7 +181,7 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { // reapply camera this._renderer._curCamera = cam; if (this._renderer._curCamera.cameraType - !== 'custom') { + === 'custom') { this._renderer.uPMatrix = this._renderer._curCamera.projMatrix; } From 1b97e17a1f9309570324ca88ae56373e6a4a72a7 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Sat, 17 Jun 2023 14:50:19 -0400 Subject: [PATCH 08/28] added safeguard for compatibility with NonWebGL sketches --- src/core/rendering.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 83d40d4020..d18c5d8716 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -157,8 +157,10 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { // copy camera - const cam = - this._renderer._curCamera.copy(); + if (this._renderer._curCamera !== undefined) { + const cam = + this._renderer._curCamera.copy(); + } // save canvas properties const props = {}; for (const key in this.drawingContext) { @@ -179,11 +181,13 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { } } // reapply camera - this._renderer._curCamera = cam; - if (this._renderer._curCamera.cameraType - === 'custom') { - this._renderer.uPMatrix = - this._renderer._curCamera.projMatrix; + if (this._renderer._curCamera !== undefined) { + this._renderer._curCamera = cam; + if (this._renderer._curCamera.cameraType + === 'custom') { + this._renderer.uPMatrix = + this._renderer._curCamera.projMatrix; + } } if (!noRedraw) { this.redraw(); From 32fef72e6daca2d40af73bc2fa358ef8a0a765ef Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Sat, 17 Jun 2023 15:09:00 -0400 Subject: [PATCH 09/28] placed cam variable in higher scope --- src/core/rendering.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index d18c5d8716..4b3de665e5 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -157,8 +157,9 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { // copy camera + let cam; if (this._renderer._curCamera !== undefined) { - const cam = + cam = this._renderer._curCamera.copy(); } // save canvas properties From 21519878ad8d3a027fd7f3b8298425d979f884b6 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Thu, 13 Jul 2023 12:55:04 -0400 Subject: [PATCH 10/28] thanks dave & inari --- src/core/rendering.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/core/rendering.js b/src/core/rendering.js index 4b3de665e5..32f448770b 100644 --- a/src/core/rendering.js +++ b/src/core/rendering.js @@ -156,12 +156,6 @@ p5.prototype.createCanvas = function(w, h, renderer) { p5.prototype.resizeCanvas = function(w, h, noRedraw) { p5._validateParameters('resizeCanvas', arguments); if (this._renderer) { - // copy camera - let cam; - if (this._renderer._curCamera !== undefined) { - cam = - this._renderer._curCamera.copy(); - } // save canvas properties const props = {}; for (const key in this.drawingContext) { @@ -170,9 +164,11 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { props[key] = val; } } - this._renderer.resize(w, h); this.width = w; this.height = h; + // Make sure width and height are updated before the renderer resizes so + // that framebuffers updated from the resize read the correct size + this._renderer.resize(w, h); // reset canvas properties for (const savedKey in props) { try { @@ -181,15 +177,6 @@ p5.prototype.resizeCanvas = function(w, h, noRedraw) { // ignore read-only property errors } } - // reapply camera - if (this._renderer._curCamera !== undefined) { - this._renderer._curCamera = cam; - if (this._renderer._curCamera.cameraType - === 'custom') { - this._renderer.uPMatrix = - this._renderer._curCamera.projMatrix; - } - } if (!noRedraw) { this.redraw(); } From dd00fcaa27e4809a1d16071b5dd177287a9aa24b Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Thu, 13 Jul 2023 12:57:55 -0400 Subject: [PATCH 11/28] lmao accidentally used git add . in the wrong dir here's the cam fix --- src/webgl/p5.Camera.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index c5a4a6cfef..1cf221a15b 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1617,11 +1617,6 @@ p5.Camera = class Camera { if (this.cameraType === 'default') { this._computeCameraDefaultSettings(); this._setDefaultCamera(); - } else { - this.perspective( - this.cameraFOV, - this._renderer.width / this._renderer.height - ); } } From 685365a6e5ab43ff066780dd0fc684d5ce1b7b25 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Mon, 31 Jul 2023 12:07:17 -0400 Subject: [PATCH 12/28] removed now unnecessary overload for FrameBufferCamera --- src/webgl/p5.Framebuffer.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 5c26c9c601..31d33f2584 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -38,26 +38,6 @@ class FramebufferCamera extends p5.Camera { this.defaultCameraNear = this.defaultEyeZ * 0.1; this.defaultCameraFar = this.defaultEyeZ * 10; } - - /** - * Resets the camera to a default perspective camera sized to match - * the p5.Framebuffer it is attached to. - * - * @method resize - * @private - */ - _resize() { - // If we're using the default camera, update the aspect ratio - if (this.cameraType === 'default') { - this._computeCameraDefaultSettings(); - this._setDefaultCamera(); - } else { - this.perspective( - this.cameraFOV, - this.fbo.width / this.fbo.height - ); - } - } } p5.FramebufferCamera = FramebufferCamera; From 409d980858e93fb38eb5efa724d582bab3d5b922 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Tue, 24 Oct 2023 21:52:42 -0400 Subject: [PATCH 13/28] made it so that functions that customize a camera set the cameraType to custom --- src/webgl/p5.Camera.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 01b9e0dde2..b011a1c420 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -465,7 +465,7 @@ p5.prototype.createCamera = function () { * camera view pans left and right across a series of rotating 3D boxes. */ p5.Camera = class Camera { - constructor(renderer) { + constructor(renderer, autoPosition = false, autoProjection = false) { // change this._renderer = renderer; this.cameraType = 'default'; @@ -1050,6 +1050,8 @@ p5.Camera = class Camera { * @private */ _rotateView(a, x, y, z) { + this.cameraType = 'custom'; + let centerX = this.centerX; let centerY = this.centerY; let centerZ = this.centerZ; @@ -1142,6 +1144,7 @@ p5.Camera = class Camera { * camera view pans left and right across a series of rotating 3D boxes. */ pan(amount) { + this.cameraType = 'custom'; const local = this._getLocalAxes(); this._rotateView(amount, local.y[0], local.y[1], local.y[2]); } @@ -1200,6 +1203,7 @@ p5.Camera = class Camera { * camera view tilts up and down across a series of rotating 3D boxes. */ tilt(amount) { + this.cameraType = 'custom'; const local = this._getLocalAxes(); this._rotateView(amount, local.x[0], local.x[1], local.x[2]); } @@ -1254,6 +1258,7 @@ p5.Camera = class Camera { * point every second . */ lookAt(x, y, z) { + this.cameraType = 'custom'; this.camera( this.eyeX, this.eyeY, @@ -1366,6 +1371,7 @@ p5.Camera = class Camera { upY, upZ ) { + this.cameraType = 'custom'; if (typeof eyeX === 'undefined') { eyeX = this.defaultEyeX; eyeY = this.defaultEyeY; @@ -1486,6 +1492,7 @@ p5.Camera = class Camera { * orientation throughout the move */ move(x, y, z) { + this.cameraType = 'custom'; const local = this._getLocalAxes(); // scale local axes by movement amounts @@ -1552,6 +1559,7 @@ p5.Camera = class Camera { * camera position changes as the user presses keys, altering view of a 3D box */ setPosition(x, y, z) { + this.cameraType = 'custom'; const diffX = x - this.eyeX; const diffY = y - this.eyeY; const diffZ = z - this.eyeZ; @@ -1746,6 +1754,7 @@ p5.Camera = class Camera { * The camera cannot be moved during that time. */ slerp(cam0, cam1, amt) { + this.cameraType = 'custom'; // If t is 0 or 1, do not interpolate and set the argument camera. if (amt === 0) { this.set(cam0); @@ -2087,6 +2096,7 @@ p5.Camera = class Camera { * @param {Number} dRadius change in radius */ _orbit(dTheta, dPhi, dRadius) { + this.cameraType = 'custom'; // Calculate the vector and its magnitude from the center to the viewpoint const diffX = this.eyeX - this.centerX; const diffY = this.eyeY - this.centerY; @@ -2157,6 +2167,7 @@ p5.Camera = class Camera { * @param {Number} dRadius change in radius */ _orbitFree(dx, dy, dRadius) { + this.cameraType = 'custom'; // Calculate the vector and its magnitude from the center to the viewpoint const diffX = this.eyeX - this.centerX; const diffY = this.eyeY - this.centerY; From 3aad5b0357c0b9d7f76e0e054a5409616e5c289e Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Tue, 24 Oct 2023 21:55:52 -0400 Subject: [PATCH 14/28] forgot to remove the extra parameters that I accidentally added --- src/webgl/p5.Camera.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index b011a1c420..703446deac 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -465,7 +465,7 @@ p5.prototype.createCamera = function () { * camera view pans left and right across a series of rotating 3D boxes. */ p5.Camera = class Camera { - constructor(renderer, autoPosition = false, autoProjection = false) { // change + constructor(renderer) { // change this._renderer = renderer; this.cameraType = 'default'; From da99eb4df7230a5c7e7521f15c135e7a722d61ce Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:01:20 -0400 Subject: [PATCH 15/28] made it so that p5.Camera.camera() uses an optional parameter for the cameraType and defaults to default --- src/webgl/p5.Camera.js | 5 +++-- test/unit/webgl/p5.Camera.js | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 703446deac..27ab350273 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1369,9 +1369,10 @@ p5.Camera = class Camera { centerZ, upX, upY, - upZ + upZ, + cameraType = 'default' ) { - this.cameraType = 'custom'; + this.cameraType = cameraType; if (typeof eyeX === 'undefined') { eyeX = this.defaultEyeX; eyeY = this.defaultEyeY; diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index b57368c677..b763cd6a2f 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -1013,4 +1013,10 @@ suite('p5.Camera', function() { assert.deepEqual(myCam2._renderer, myp5._renderer); }); }); + + suite('Camera attributes after resizing', function() { + test('Camera position is the same', function() { + + }); + }); }); From cdff3ea55883e6741272dcee3826c920eb5490cb Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:31:23 -0400 Subject: [PATCH 16/28] added some changes so that default cameras only reset their fov as suggested by dave --- src/webgl/p5.Camera.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 27ab350273..2a427a6964 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1995,8 +1995,9 @@ p5.Camera = class Camera { _resize() { // If we're using the default camera, update the aspect ratio if (this.cameraType === 'default') { - this._computeCameraDefaultSettings(); + this.cameraFOV = this.defaultCameraFOV; this._setDefaultCamera(); + this.perspective(); } } From 6512043a84d50bfab5db8b495989b5a142e44960 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:36:42 -0400 Subject: [PATCH 17/28] removed the custom setters for cameraType since position is now longer automatically reset for cameras of cameraType default when resizing --- src/webgl/p5.Camera.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 2a427a6964..12228fb1d9 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1050,8 +1050,6 @@ p5.Camera = class Camera { * @private */ _rotateView(a, x, y, z) { - this.cameraType = 'custom'; - let centerX = this.centerX; let centerY = this.centerY; let centerZ = this.centerZ; @@ -1144,7 +1142,6 @@ p5.Camera = class Camera { * camera view pans left and right across a series of rotating 3D boxes. */ pan(amount) { - this.cameraType = 'custom'; const local = this._getLocalAxes(); this._rotateView(amount, local.y[0], local.y[1], local.y[2]); } @@ -1203,7 +1200,6 @@ p5.Camera = class Camera { * camera view tilts up and down across a series of rotating 3D boxes. */ tilt(amount) { - this.cameraType = 'custom'; const local = this._getLocalAxes(); this._rotateView(amount, local.x[0], local.x[1], local.x[2]); } @@ -1258,7 +1254,6 @@ p5.Camera = class Camera { * point every second . */ lookAt(x, y, z) { - this.cameraType = 'custom'; this.camera( this.eyeX, this.eyeY, @@ -1493,7 +1488,6 @@ p5.Camera = class Camera { * orientation throughout the move */ move(x, y, z) { - this.cameraType = 'custom'; const local = this._getLocalAxes(); // scale local axes by movement amounts @@ -1560,7 +1554,6 @@ p5.Camera = class Camera { * camera position changes as the user presses keys, altering view of a 3D box */ setPosition(x, y, z) { - this.cameraType = 'custom'; const diffX = x - this.eyeX; const diffY = y - this.eyeY; const diffZ = z - this.eyeZ; @@ -1755,7 +1748,6 @@ p5.Camera = class Camera { * The camera cannot be moved during that time. */ slerp(cam0, cam1, amt) { - this.cameraType = 'custom'; // If t is 0 or 1, do not interpolate and set the argument camera. if (amt === 0) { this.set(cam0); @@ -2098,7 +2090,6 @@ p5.Camera = class Camera { * @param {Number} dRadius change in radius */ _orbit(dTheta, dPhi, dRadius) { - this.cameraType = 'custom'; // Calculate the vector and its magnitude from the center to the viewpoint const diffX = this.eyeX - this.centerX; const diffY = this.eyeY - this.centerY; @@ -2169,7 +2160,6 @@ p5.Camera = class Camera { * @param {Number} dRadius change in radius */ _orbitFree(dx, dy, dRadius) { - this.cameraType = 'custom'; // Calculate the vector and its magnitude from the center to the viewpoint const diffX = this.eyeX - this.centerX; const diffY = this.eyeY - this.centerY; From 58b386293802a09ffeb0a9f8be19c8f586dc62a6 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:39:56 -0400 Subject: [PATCH 18/28] added the code from dave's example for keeping the camera z constant --- src/webgl/p5.Camera.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 12228fb1d9..6af7eca6bb 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1948,12 +1948,12 @@ p5.Camera = class Camera { // @TODO: combine this function with _setDefaultCamera to compute these values // as-needed _computeCameraDefaultSettings() { - this.defaultCameraFOV = 60 / 180 * Math.PI; + this.defaultCameraFOV = + 2 * Math.atan(this._renderer.height / 2 / this.defaultEyeZ); this.defaultAspectRatio = this._renderer.width / this._renderer.height; this.defaultEyeX = 0; this.defaultEyeY = 0; - this.defaultEyeZ = - this._renderer.height / 2.0 / Math.tan(this.defaultCameraFOV / 2.0); + this.defaultEyeZ = 800; this.defaultCenterX = 0; this.defaultCenterY = 0; this.defaultCenterZ = 0; From 055e1339511ec6d88ab6a567a6c329b59fce2d60 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:41:40 -0400 Subject: [PATCH 19/28] removed the default cameraType setter in p5.Camera.camera() --- src/webgl/p5.Camera.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 6af7eca6bb..5812f43c08 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1364,10 +1364,8 @@ p5.Camera = class Camera { centerZ, upX, upY, - upZ, - cameraType = 'default' + upZ ) { - this.cameraType = cameraType; if (typeof eyeX === 'undefined') { eyeX = this.defaultEyeX; eyeY = this.defaultEyeY; From 9858a688ec8640c3f46fd4524648146396469db3 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:43:31 -0400 Subject: [PATCH 20/28] swapped the lines so that defaultEyeZ's value of 800 applies in the calculations for defaultCameraFOV --- src/webgl/p5.Camera.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 5812f43c08..922ccee2b2 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1946,12 +1946,12 @@ p5.Camera = class Camera { // @TODO: combine this function with _setDefaultCamera to compute these values // as-needed _computeCameraDefaultSettings() { - this.defaultCameraFOV = - 2 * Math.atan(this._renderer.height / 2 / this.defaultEyeZ); this.defaultAspectRatio = this._renderer.width / this._renderer.height; this.defaultEyeX = 0; this.defaultEyeY = 0; this.defaultEyeZ = 800; + this.defaultCameraFOV = + 2 * Math.atan(this._renderer.height / 2 / this.defaultEyeZ); this.defaultCenterX = 0; this.defaultCenterY = 0; this.defaultCenterZ = 0; From 627836c1e25eda6a583f156a34c6a054d4ca7c75 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 19:54:48 -0400 Subject: [PATCH 21/28] removed _setDefaultCamera() and added back _computeCameraDefaultSettings() due to a mixup and updated the aspectRatio --- src/webgl/p5.Camera.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 922ccee2b2..4a9b83c0fd 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -1985,8 +1985,9 @@ p5.Camera = class Camera { _resize() { // If we're using the default camera, update the aspect ratio if (this.cameraType === 'default') { + this._computeCameraDefaultSettings(); this.cameraFOV = this.defaultCameraFOV; - this._setDefaultCamera(); + this.aspectRatio = this.defaultAspectRatio; this.perspective(); } } From 7f597ca17a3971f5310e71f790efd5f2766fb2db Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Wed, 25 Oct 2023 20:43:39 -0400 Subject: [PATCH 22/28] Change order of applying perspective scale to get better fidelity joins on thin lines --- src/webgl/shaders/line.vert | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/webgl/shaders/line.vert b/src/webgl/shaders/line.vert index 406a7012d6..4b6d032a1f 100644 --- a/src/webgl/shaders/line.vert +++ b/src/webgl/shaders/line.vert @@ -170,9 +170,9 @@ void main() { // find where the lines intersect to find the elbow of the join vec2 c = (posp.xy/posp.w + vec2(1.,1.)) * 0.5 * uViewport.zw; vec2 intersection = lineIntersection( - c + (side * normalIn * uStrokeWeight / 2.) * curPerspScale, + c + (side * normalIn * uStrokeWeight / 2.), tangentIn, - c + (side * normalOut * uStrokeWeight / 2.) * curPerspScale, + c + (side * normalOut * uStrokeWeight / 2.), tangentOut ); offset = (intersection - c); @@ -187,9 +187,9 @@ void main() { offset *= maxMag / mag; } } else if (sideEnum == 1.) { - offset = side * normalIn * curPerspScale * uStrokeWeight / 2.; + offset = side * normalIn * uStrokeWeight / 2.; } else if (sideEnum == 3.) { - offset = side * normalOut * curPerspScale * uStrokeWeight / 2.; + offset = side * normalOut * uStrokeWeight / 2.; } } if (uStrokeJoin == STROKE_JOIN_BEVEL) { @@ -208,12 +208,12 @@ void main() { // extends out from the line float tangentOffset = abs(aSide) - 1.; offset = (normal * normalOffset + tangent * tangentOffset) * - uStrokeWeight * 0.5 * curPerspScale; + uStrokeWeight * 0.5; vMaxDist = uStrokeWeight / 2.; } - vPosition = vCenter + offset / curPerspScale; + vPosition = vCenter + offset; - gl_Position.xy = p.xy + offset.xy; + gl_Position.xy = p.xy + offset.xy * curPerspScale; gl_Position.zw = p.zw; vColor = (uUseLineColor ? aVertexColor : uMaterialColor); From 84871491a38dc4b8cafb83d432e0fdae937a944f Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Wed, 25 Oct 2023 21:18:05 -0400 Subject: [PATCH 23/28] Update tests --- src/webgl/p5.Framebuffer.js | 6 ++---- test/unit/webgl/p5.Camera.js | 14 +++++++------- test/unit/webgl/p5.Framebuffer.js | 15 +++++++++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/webgl/p5.Framebuffer.js b/src/webgl/p5.Framebuffer.js index 7111d23541..7642ccf549 100644 --- a/src/webgl/p5.Framebuffer.js +++ b/src/webgl/p5.Framebuffer.js @@ -33,10 +33,8 @@ class FramebufferCamera extends p5.Camera { _computeCameraDefaultSettings() { super._computeCameraDefaultSettings(); this.defaultAspectRatio = this.fbo.width / this.fbo.height; - this.defaultEyeZ = - this.fbo.height / 2.0 / Math.tan(this.defaultCameraFOV / 2.0); - this.defaultCameraNear = this.defaultEyeZ * 0.1; - this.defaultCameraFar = this.defaultEyeZ * 10; + this.defaultCameraFOV = + 2 * Math.atan(this.fbo.height / 2 / this.defaultEyeZ); } } diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index b763cd6a2f..e756a0c8c0 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -687,10 +687,10 @@ suite('p5.Camera', function() { test('perspective() with no parameters specified (sets default)', function() { var expectedMatrix = new Float32Array([ - 1.7320507764816284,0,0,0, - 0,-1.7320507764816284,0,0, + 16,0,0,0, + 0,-16,0,0, 0,0,-1.0202020406723022,-1, - 0,0,-17.49546241760254,0 + 0,0,-161.6161651611328,0 ]); myCam.perspective(); @@ -726,10 +726,10 @@ suite('p5.Camera', function() { test('frustum() with no parameters specified (sets default)', function() { var expectedMatrix = new Float32Array([ - 1.7320507764816284, 0, 0, 0, - 0, 1.7320507764816284, 0, 0, - 0, -0, -1.0202020406723022, -1, - 0, 0, -17.49546241760254, 0 + 16,0,0,0, + 0,16,0,0, + 0,-0,-1.0202020406723022,-1, + 0,0,-161.6161651611328,0 ]); myCam.frustum(); diff --git a/test/unit/webgl/p5.Framebuffer.js b/test/unit/webgl/p5.Framebuffer.js index f2dbe0f622..e87e6240e7 100644 --- a/test/unit/webgl/p5.Framebuffer.js +++ b/test/unit/webgl/p5.Framebuffer.js @@ -221,7 +221,7 @@ suite('p5.Framebuffer', function() { myp5.plane(myp5.width, -myp5.height); // Just check the red channel, other channels might vary across browsers - assert.equal(myp5.get(5, 5)[0], 221); + assert.equal(myp5.get(5, 5)[0], 232); }); }); @@ -287,7 +287,11 @@ suite('p5.Framebuffer', function() { suite('the default camera', function() { test('it uses the aspect ratio of the framebuffer', function() { expect(fbo.defaultCamera.aspectRatio).to.equal(5 / 15); - const z = -fbo.height / 2.0 / Math.tan(Math.PI / 3 / 2); + expect(fbo.defaultCamera.cameraFOV).to.be.closeTo( + 2.0 * Math.atan(15 / 2 / 800), + 0.01 + ); + const z = -800; const expectedCameraMatrix = [ 1, 0, 0, 0, 0, 1, 0, 0, @@ -303,8 +307,11 @@ suite('p5.Framebuffer', function() { test('it updates the aspect ratio after resizing', function() { fbo.resize(20, 10); expect(fbo.defaultCamera.aspectRatio).to.equal(2); - - const z = -fbo.height / 2.0 / Math.tan(Math.PI / 3 / 2); + expect(fbo.defaultCamera.cameraFOV).to.be.closeTo( + 2.0 * Math.atan(10 / 2 / 800), + 0.01 + ); + const z = -800; const expectedCameraMatrix = [ 1, 0, 0, 0, 0, 1, 0, 0, From 70bee38a55258808411a49aaa759716d22b1f724 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 23:41:30 -0400 Subject: [PATCH 24/28] added camera position test --- test/unit/webgl/p5.Camera.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index e756a0c8c0..ec0e88f0d5 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -1016,7 +1016,33 @@ suite('p5.Camera', function() { suite('Camera attributes after resizing', function() { test('Camera position is the same', function() { + myp5.createCanvas(1, 1); + myp5.noStroke(); + myp5.pixelDensity(1); + let cam = myp5.createCamera(); + + myp5.fill(255, 0, 0); + + const testShape = () => { + myp5.clear(); + myp5.rect(-myp5.width, -myp5.height, myp5.width * 2, myp5.height * 2); + }; + + testShape(); + assert.deepEqual(myp5.get(0, 0), [255, 0, 0, 255]); + assert.equal(cam.eyeX, 0); + + cam.move(10, 0, 0); + testShape(); + assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); + assert.equal(cam.eyeX, 10); + + resizeCanvas(2, 1); + resizeCanvas(1, 1); + testShape(); + assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); + assert.equal(cam.eyeX, 10); }); }); -}); +}); \ No newline at end of file From 9142e132f4b4d727ec017e24f3d30977724958e1 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 23:48:36 -0400 Subject: [PATCH 25/28] added rotation test and changed it so that it uses a WEBGL canvas --- test/unit/webgl/p5.Camera.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index ec0e88f0d5..3b6399b744 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -1016,7 +1016,7 @@ suite('p5.Camera', function() { suite('Camera attributes after resizing', function() { test('Camera position is the same', function() { - myp5.createCanvas(1, 1); + myp5.createCanvas(1, 1, WEBGL); myp5.noStroke(); myp5.pixelDensity(1); @@ -1044,5 +1044,32 @@ suite('p5.Camera', function() { assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); assert.equal(cam.eyeX, 10); }); + + test('Camera rotation is the same', function() { + myp5.createCanvas(1, 1, WEBGL); + myp5.noStroke(); + myp5.pixelDensity(1); + + let cam = myp5.createCamera(); + + myp5.fill(255, 0, 0); + + const testShape = () => { + myp5.clear(); + myp5.rect(-myp5.width, -myp5.height, myp5.width * 2, myp5.height * 2); + }; + + testShape(); + assert.deepEqual(myp5.get(0, 0), [255, 0, 0, 255]); + + cam.pan(10); + testShape(); + assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); + + resizeCanvas(2, 1); + resizeCanvas(1, 1); + testShape(); + assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); + }); }); }); \ No newline at end of file From a50f4f978f1035c40cc5aa6d58e1b183a95f3cb4 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 25 Oct 2023 23:54:47 -0400 Subject: [PATCH 26/28] added myp5. in front of WEBGL --- test/unit/webgl/p5.Camera.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index 3b6399b744..4cd6433faa 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -1016,7 +1016,7 @@ suite('p5.Camera', function() { suite('Camera attributes after resizing', function() { test('Camera position is the same', function() { - myp5.createCanvas(1, 1, WEBGL); + myp5.createCanvas(1, 1, myp5.WEBGL); myp5.noStroke(); myp5.pixelDensity(1); @@ -1046,7 +1046,7 @@ suite('p5.Camera', function() { }); test('Camera rotation is the same', function() { - myp5.createCanvas(1, 1, WEBGL); + myp5.createCanvas(1, 1, myp5.WEBGL); myp5.noStroke(); myp5.pixelDensity(1); From 85bdf92af43e9a61410335507ad7dd251e7e79d7 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Thu, 26 Oct 2023 00:05:15 -0400 Subject: [PATCH 27/28] added myp5. in front of resizeCanvas() --- test/unit/webgl/p5.Camera.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/webgl/p5.Camera.js b/test/unit/webgl/p5.Camera.js index 4cd6433faa..1c8fb7214b 100644 --- a/test/unit/webgl/p5.Camera.js +++ b/test/unit/webgl/p5.Camera.js @@ -1038,8 +1038,8 @@ suite('p5.Camera', function() { assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); assert.equal(cam.eyeX, 10); - resizeCanvas(2, 1); - resizeCanvas(1, 1); + myp5.resizeCanvas(2, 1); + myp5.resizeCanvas(1, 1); testShape(); assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); assert.equal(cam.eyeX, 10); @@ -1066,8 +1066,8 @@ suite('p5.Camera', function() { testShape(); assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); - resizeCanvas(2, 1); - resizeCanvas(1, 1); + myp5.resizeCanvas(2, 1); + myp5.resizeCanvas(1, 1); testShape(); assert.deepEqual(myp5.get(0, 0), [0, 0, 0, 0]); }); From 71fc1340448a676d9cbb3947fe52bfc2c51ba8b5 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Thu, 26 Oct 2023 17:03:47 -0400 Subject: [PATCH 28/28] removed a comment that I accidentally added --- src/webgl/p5.Camera.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 4a9b83c0fd..2a9d42eb18 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -465,7 +465,7 @@ p5.prototype.createCamera = function () { * camera view pans left and right across a series of rotating 3D boxes. */ p5.Camera = class Camera { - constructor(renderer) { // change + constructor(renderer) { this._renderer = renderer; this.cameraType = 'default';