-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solves issue #6519 #6549
Solves issue #6519 #6549
Conversation
src/webgl/p5.Camera.js
Outdated
* | ||
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/webgl/p5.Camera.js
Outdated
* | ||
* 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than saying "position the camera correctly", maybe we could phrase this like:
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.
Note that I also put backticks around the math bit, since that refers to code.
src/webgl/p5.Camera.js
Outdated
* 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 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can probably omit this step, since there actually isn't a variable to set here, we'll just pass it right into perspective
.
src/webgl/p5.Camera.js
Outdated
* | ||
* 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super tiny tweak, but can we take out "simply" at the start? We generally try to keep things instructional without passing judgment on how easy or hard things are.
src/webgl/p5.Camera.js
Outdated
* 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can put backticks around this too to format it like code:
* perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10); | |
* `perspective(fovy, width / height, cameraDistance / 10, cameraDistance * 10);` |
src/webgl/p5.Camera.js
Outdated
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can maybe improve the readability of this list, perhaps by turning it into a bullet list?
To do so, we need to put a -
before each item, and take out the empty lines between them. I also think it might flow better once in a bullet list if we use a colon afterwards instead of a dash. Lastly, since each of these is a variable name, we can put them in backticks:
src/webgl/p5.Camera.js
Outdated
* | ||
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. | |
* 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. |
src/webgl/p5.Camera.js
Outdated
* | ||
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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. | |
* far - The default value for the far clipping plane is 8000, which is 10 times the default distance from the camera to its subject. |
src/webgl/p5.Camera.js
Outdated
@@ -156,7 +176,7 @@ p5.prototype.camera = function (...args) { | |||
* | |||
* rotateX(-0.3); | |||
* rotateY(-0.2); | |||
* translate(0, 0, -50); | |||
* translate(0, 0, -100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to play around with this some more. It looks like it's getting clipped the other way now:
Screen.Recording.2023-11-14.at.6.27.53.PM.mov
Thanks @davepagurek for these suggestions ..! I'll just look into these and get back to u soon. |
@davepagurek I have tried to implement what you have suggested , But I am not sure about the translate distance setting to 85 in the negative z direction. whereas on the original P5 reference, the cubes are visible : |
I think the difference is that now, the camera is a fixed distance back (800), it was likely closer to the objects before. How do you these settings look to you: Translating closer, and translating before rotating to keep things in frame: translate(0, 0, 500);
rotateX(-0.3);
rotateY(-0.2); |
Great! Thanks @davepagurek ..!! This absolutely works fine. Also, I would like to add that similar is the case for ortho also , should I replicate the same thing to that also and then commit the changes. Without adding translate to 500: |
That would be great if you could fix those too, thanks! |
Well after going through the camera methods written in camera.js file, I observed this issue with so many methods . Rather than changing the existing code for the examples for individual methods, I think we should change the default camera settings which are causing this issue in in the local development environment. What's your call on this @davepagurek ?? |
I think the change that did this was the exact change that this PR is improving the documentation for, changing the camera behaviour to have a position that is independent of the field of view. Previously, the camera would move itself forward or backward when changing the window size in order to keep a fixed field of view, but that caused issues when using a custom camera, as it is unclear what should happen to cameras that have been manually positioned. Now that the camera positioning works a bit differently, it makes sense that these examples need to update their camera code a bit. The alternate approach, where the behaviour would be completely consistent for the examples, we'd likely have to undo #6216, and rather than use a fixed field of view, move the camera closer to/farther from its subject as the window resizes in order to still fix the bugs related to the camera resetting. Those changes are also nontrivial, so I think it's ok in this case to just update the camera examples. |
Looks great! One last thing, it looks like the docs for |
Thanks a lot @davepagurek for your suggestions.! Learnt a lot solving this issue. Please let me know if some other changes are to be made to this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for your work on this!
Many questions remain. It's one thing to not execute orbitControl(), but why didn't you check other examples as well? |
Solves issue #6519
Changes:
I have tried to incorporate all the changes suggested by @davepagurek . Please let me know if something else needs to be changed. Thank You..!
Link to the changes made: src/webgl/p5.Camera.js
Screenshots of the change:
Change in translate():
Documentation update:
PR Checklist
npm run lint
passes