From 3d8876c59a6facb729dc2da4ed8a684dd770b2f2 Mon Sep 17 00:00:00 2001 From: Garima Date: Sat, 11 Nov 2023 13:53:14 +0530 Subject: [PATCH 1/4] Solves issue #6519 --- src/webgl/p5.Camera.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 3d20076e2d..71ac7f5cde 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -127,9 +127,29 @@ p5.prototype.camera = function (...args) { * vertical field of view, aspect ratio (usually width/height), and near and far * clipping planes. * - * If no parameters are given, the following default is used: - * perspective(PI/3, width/height, eyeZ/10, eyeZ*10), - * where eyeZ is equal to ((height/2) / tan(PI/6)). + * If no parameters are given, the default values are used as: + * + * fov- The default field of view for the camera is such that the full height of renderer is visible when it is positioned at a default distance of 800 units from the camera. + * + * aspect- The default aspect ratio is the ratio of renderer's width to renderer's height. + * + * near - The default value for the near clipping plane is 0.1 times the default distance from the camera to the point it is looking at i.e 800. + * + * far - The default value for the far clipping plane is 10 times the default distance from the camera to the point it is looking at i.e 800. + * + * If you prefer a fixed field of view, follow these steps: + * + * 1.Choose your desired field of view angle (`fovy`). This is how wide the camera can see. + * + * 2.To position the camera correctly, use the formula: + * cameraDistance = (height / 2) / tan(fovy / 2); + * This ensures that you can see the entire width across horizontally and height across vertically at the fixed field of view. + * + * 3.Set the near value to cameraDistance / 10 and the far value to cameraDistance * 10 . + * + * 4.Simply, call perspective with the chosen field of view, canvas aspect ratio, and near/far values: + * perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10); + * * @method perspective * @for p5 * @param {Number} [fovy] camera frustum vertical field of view, @@ -156,7 +176,7 @@ p5.prototype.camera = function (...args) { * * rotateX(-0.3); * rotateY(-0.2); - * translate(0, 0, -50); + * translate(0, 0, -100); * * push(); * translate(-15, 0, sin(frameCount / 30) * 95); From b482b2d99970352873494d3859e35292bf0ac267 Mon Sep 17 00:00:00 2001 From: Garima Date: Wed, 15 Nov 2023 20:23:06 +0530 Subject: [PATCH 2/4] Updated reference for perspective() --- src/webgl/p5.Camera.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 71ac7f5cde..2329c4fa6a 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -129,26 +129,16 @@ p5.prototype.camera = function (...args) { * * If no parameters are given, the default values are used as: * - * fov- The default field of view for the camera is such that the full height of renderer is visible when it is positioned at a default distance of 800 units from the camera. - * - * aspect- The default aspect ratio is the ratio of renderer's width to renderer's height. - * - * near - The default value for the near clipping plane is 0.1 times the default distance from the camera to the point it is looking at i.e 800. - * - * far - The default value for the far clipping plane is 10 times the default distance from the camera to the point it is looking at i.e 800. + * - `fov` : The default field of view for the camera is such that the full height of renderer is visible when it is positioned at a default distance of 800 units from the camera. + * - `aspect` : The default aspect ratio is the ratio of renderer's width to renderer's height. + * - `near` : The default value for the near clipping plane is 80, which is 0.1 times the default distance from the camera to its subject. + * - `far` : The default value for the far clipping plane is 8000, which is 10 times the default distance from the camera to its subject. * * If you prefer a fixed field of view, follow these steps: - * - * 1.Choose your desired field of view angle (`fovy`). This is how wide the camera can see. - * - * 2.To position the camera correctly, use the formula: - * cameraDistance = (height / 2) / tan(fovy / 2); - * This ensures that you can see the entire width across horizontally and height across vertically at the fixed field of view. - * - * 3.Set the near value to cameraDistance / 10 and the far value to cameraDistance * 10 . - * - * 4.Simply, call perspective with the chosen field of view, canvas aspect ratio, and near/far values: - * perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10); + * 1. Choose your desired field of view angle (`fovy`). This is how wide the camera can see. + * 2. To ensure that you can see the entire width across horizontally and height across vertically, place the camera a distance of `(height / 2) / tan(fovy / 2)` back from its subject. + * 3. Call perspective with the chosen field of view, canvas aspect ratio, and near/far values: + * `perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10);` * * @method perspective * @for p5 @@ -176,7 +166,7 @@ p5.prototype.camera = function (...args) { * * rotateX(-0.3); * rotateY(-0.2); - * translate(0, 0, -100); + * translate(0, 0, -85); * * push(); * translate(-15, 0, sin(frameCount / 30) * 95); From 32d83f75ef45b7458d6d271d649af97f148ae258 Mon Sep 17 00:00:00 2001 From: Garima Date: Thu, 23 Nov 2023 12:20:20 +0530 Subject: [PATCH 3/4] Updated perspective and ortho methods example code --- src/webgl/p5.Camera.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/webgl/p5.Camera.js b/src/webgl/p5.Camera.js index 2329c4fa6a..d83e777868 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -164,9 +164,9 @@ p5.prototype.camera = function (...args) { * orbitControl(); * normalMaterial(); * + * translate(0, 0, 550); * rotateX(-0.3); * rotateY(-0.2); - * translate(0, 0, -85); * * push(); * translate(-15, 0, sin(frameCount / 30) * 95); @@ -229,6 +229,7 @@ p5.prototype.perspective = function (...args) { * orbitControl(); * normalMaterial(); * + * translate(0,0,500); * rotateX(0.2); * rotateY(-0.2); * push(); @@ -759,9 +760,9 @@ p5.Camera = class Camera { * orbitControl(); * normalMaterial(); * + * translate(0, 0, 550); * rotateX(-0.3); * rotateY(-0.2); - * translate(0, 0, -50); * * push(); * translate(-15, 0, sin(frameCount / 30) * 95); @@ -877,7 +878,7 @@ p5.Camera = class Camera { * background(200); * orbitControl(); * normalMaterial(); - * + * translate(0,0,500); * rotateX(0.2); * rotateY(-0.2); * push(); From fe8759503c1d890afced5f52edca558a5527c79f Mon Sep 17 00:00:00 2001 From: Garima Date: Fri, 24 Nov 2023 02:06:16 +0530 Subject: [PATCH 4/4] Updated docs for frustum method in both p5 and p5.Camera --- 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 d83e777868..64d64105e5 100644 --- a/src/webgl/p5.Camera.js +++ b/src/webgl/p5.Camera.js @@ -296,7 +296,7 @@ p5.prototype.ortho = function (...args) { * background(200); * orbitControl(); * normalMaterial(); - * + * translate(0,0,700); * rotateY(-0.2); * rotateX(-0.3); * push(); @@ -977,7 +977,7 @@ p5.Camera = class Camera { * background(200); * orbitControl(); * normalMaterial(); - * + * translate(0,0,700); * rotateY(-0.2); * rotateX(-0.3); * push();