Skip to content

Commit ecaea3a

Browse files
authored
Merge pull request #6549 from Garima3110/perspective
Solves issue #6519
2 parents dcfe3bc + f4948c4 commit ecaea3a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/webgl/p5.Camera.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,19 @@ p5.prototype.camera = function (...args) {
127127
* vertical field of view, aspect ratio (usually width/height), and near and far
128128
* clipping planes.
129129
*
130-
* If no parameters are given, the following default is used:
131-
* perspective(PI/3, width/height, eyeZ/10, eyeZ*10),
132-
* where eyeZ is equal to ((height/2) / tan(PI/6)).
130+
* If no parameters are given, the default values are used as:
131+
*
132+
* - `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.
133+
* - `aspect` : The default aspect ratio is the ratio of renderer's width to renderer's height.
134+
* - `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.
135+
* - `far` : The default value for the far clipping plane is 8000, which is 10 times the default distance from the camera to its subject.
136+
*
137+
* If you prefer a fixed field of view, follow these steps:
138+
* 1. Choose your desired field of view angle (`fovy`). This is how wide the camera can see.
139+
* 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.
140+
* 3. Call perspective with the chosen field of view, canvas aspect ratio, and near/far values:
141+
* `perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10);`
142+
*
133143
* @method perspective
134144
* @for p5
135145
* @param {Number} [fovy] camera frustum vertical field of view,
@@ -154,9 +164,9 @@ p5.prototype.camera = function (...args) {
154164
* orbitControl();
155165
* normalMaterial();
156166
*
167+
* translate(0, 0, 550);
157168
* rotateX(-0.3);
158169
* rotateY(-0.2);
159-
* translate(0, 0, -50);
160170
*
161171
* push();
162172
* translate(-15, 0, sin(frameCount / 30) * 95);
@@ -219,6 +229,7 @@ p5.prototype.perspective = function (...args) {
219229
* orbitControl();
220230
* normalMaterial();
221231
*
232+
* translate(0,0,500);
222233
* rotateX(0.2);
223234
* rotateY(-0.2);
224235
* push();
@@ -285,7 +296,7 @@ p5.prototype.ortho = function (...args) {
285296
* background(200);
286297
* orbitControl();
287298
* normalMaterial();
288-
*
299+
* translate(0,0,700);
289300
* rotateY(-0.2);
290301
* rotateX(-0.3);
291302
* push();
@@ -749,9 +760,9 @@ p5.Camera = class Camera {
749760
* orbitControl();
750761
* normalMaterial();
751762
*
763+
* translate(0, 0, 550);
752764
* rotateX(-0.3);
753765
* rotateY(-0.2);
754-
* translate(0, 0, -50);
755766
*
756767
* push();
757768
* translate(-15, 0, sin(frameCount / 30) * 95);
@@ -867,7 +878,7 @@ p5.Camera = class Camera {
867878
* background(200);
868879
* orbitControl();
869880
* normalMaterial();
870-
*
881+
* translate(0,0,500);
871882
* rotateX(0.2);
872883
* rotateY(-0.2);
873884
* push();
@@ -966,7 +977,7 @@ p5.Camera = class Camera {
966977
* background(200);
967978
* orbitControl();
968979
* normalMaterial();
969-
*
980+
* translate(0,0,700);
970981
* rotateY(-0.2);
971982
* rotateX(-0.3);
972983
* push();

0 commit comments

Comments
 (0)