Skip to content

Commit 9d478f3

Browse files
committed
Solves issue #6519
1 parent e508b44 commit 9d478f3

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/webgl/p5.Camera.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,36 +122,42 @@ p5.prototype.camera = function (...args) {
122122
* that are close to the camera appear their actual size while those
123123
* that are further away from the camera appear smaller.
124124
*
125+
*
125126
* The parameters to this function define the viewing frustum
126127
* (the truncated pyramid within which objects are seen by the camera) through
127128
* vertical field of view, aspect ratio (usually width/height), and near and far
128129
* clipping planes.
129130
*
130-
* If no parameters are given, the default values are used, with a fixed location and a variable field of view.
131-
* @method perspective
132-
* @for p5
133-
* @param {Number} [fovy] - camera frustum vertical field of view,
134-
* from bottom to top of view, in <a href="#/p5/angleMode">angleMode</a> units.
135-
* The default value is now variable and based on the canvas size as:
136-
* this.defaultEyeZ = 800;
137-
* defaultCameraFOV = 2 * Math.atan(this._renderer.height / 2 / this.defaultEyeZ);
131+
* If no parameters are given, the default values are used as:
138132
*
139-
* @param {Number} [aspect] camera frustum aspect ratio .The default value = this._renderer.width / this._renderer.height;
140-
* @param {Number} [near] frustum near plane length or the near clipping plane. The default value = this.defaultEyeZ * 0.1;
141-
* @param {Number} [far] frustum far plane length or the far clipping plane. The default value = this.defaultEyeZ * 10;
142133
*
143-
* However,If you prefer a fixed field of view, you can use the old defaults:
134+
* 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.
144135
*
145-
* - Field of view: PI/3 (60 degrees)
146-
* - Canvas aspect ratio: width / height
147-
* - Near clipping plane: eyeZ / 10
148-
* - Far clipping plane: eyeZ * 10
136+
* aspect- The default aspect ratio is the ratio of renderer's width to renderer's height.
149137
*
150-
* @example
151-
* Set a fixed field of view
152-
* perspective(PI/3, width / height, eyeZ / 10, eyeZ * 10);
153-
* where eyeZ is equal to ((height/2) / tan(PI/6)).
138+
* 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.
139+
*
140+
* 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.
141+
*
142+
* If you prefer a fixed field of view, follow these steps:
154143
*
144+
* 1.Choose your desired field of view angle (`fovy`). This is how wide the camera can see.
145+
*
146+
* 2.To position the camera correctly, use the formula:
147+
* cameraDistance = (height / 2) / tan(fovy / 2);
148+
* This ensures that you can see the entire width across horizontally and height across vertically at the fixed field of view.
149+
*
150+
* 3.Set the near value to cameraDistance / 10 and the far value to cameraDistance * 10 .
151+
*
152+
* 4.Simply, call perspective with the chosen field of view, canvas aspect ratio, and near/far values:
153+
* perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10);
154+
* @method perspective
155+
* @for p5
156+
* @param {Number} [fovy] camera frustum vertical field of view,
157+
* from bottom to top of view, in <a href="#/p5/angleMode">angleMode</a> units.
158+
* @param {Number} [aspect] camera frustum aspect ratio
159+
* @param {Number} [near] frustum near plane length
160+
* @param {Number} [far] frustum far plane length
155161
* @chainable
156162
* @example
157163
* <div>
@@ -171,7 +177,7 @@ p5.prototype.camera = function (...args) {
171177
*
172178
* rotateX(-0.3);
173179
* rotateY(-0.2);
174-
* translate(0, 0, -50);
180+
* translate(0, 0, -100);
175181
*
176182
* push();
177183
* translate(-15, 0, sin(frameCount / 30) * 95);

0 commit comments

Comments
 (0)