From 3d8876c59a6facb729dc2da4ed8a684dd770b2f2 Mon Sep 17 00:00:00 2001 From: Garima Date: Sat, 11 Nov 2023 13:53:14 +0530 Subject: [PATCH] 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);