-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Created fix for camera settings getting reset each time resizeCanvas() is called #6216
Conversation
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page! |
This is the solution for issue #6203. |
Thanks for taking this on! Do you think it's equivalent to take out the else branch here? Lines 1615 to 1626 in d2b5d5e
If it is equivalent, it might be better to make the code change there to avoid doing some work then undoing it |
About the resize function, tbh I'm not very sure, but they don't look like they do the same things is all of I have to say ig lol. |
I combined my previous work with your advice inaridarkfox4231 and now |
|
lol dw it's fine, I didn't realize that there was a problem with |
Just thought of a few more things to consider, one is that Framebuffers also have a default camera that gets resized here, so we probably want to implement this in both spots: p5.js/src/webgl/p5.Framebuffer.js Lines 677 to 685 in 63bea68
Also, if we copy the camera and set
The One other thing, it would be great to add a unit test -- maybe something like, make a canvas, set |
tbh I didn't know that p5.Framebuffer was part of the p5.js library lol. I'll implement smth for that when I can. Also yeah, I sorta forgot about the outside reference to camera part. Originally I only copied the matrices because of that, but ig I just forgot. I'll make it so that it just copies the attributes later. I think I'll probably just create a class and iterate over each of the key value pairs in order to write them. Their attributes like the matrices however would have to have their references replaced which would be a bit annoying if someone were to have cached those tho lol, altho at this point basically unavoidable. I'll try to write smth for the unit test too when I can. |
I think it's ok to replace the matrix properties, we also haven't publicly documented their existence, so I think it's fair game to modify that without it causing a breaking change 🙂 |
lol it's fine. also yeah ig it'd probably be fine since they rn't documented. |
I'll be a bit busy, but I'll add those to the pull request when I can. |
The problem right now is indeed about the behavior of the camera, but the problem with the camera is the fact that |
I fixed the Resolves #[Add issue number here]. Also, I discussed with davepagurek and he seems to agree that it's a bug. For an example, a lot of programs oftentimes end up using the camera to store their values for movement among other things and even those that don't most likely don't cache them separately outside of the camera. For a 3d application like a game or any other sort of software a simple resize could easily break their code base. Plus, even if we were to say that since the WebGL uniforms reset so everything else should reset too, if you look at the function p5.js is clearly making an effort to cache and restore canvas values, so it's probably more so of a bug that they managed to do it for basically everything except for the camera. |
As for creating a sketch for this, I feel like it's unnecessary. I could create a sketch demonstrating a moving camera that gets reset upon the window getting resized due to wanting to resize with the window, but that'd only display the same thing as what I said. If u mean getting a full project that has a problem with this, I feel that that's unnecessary. |
I'm confused how you wouldn't have understood the change and it's reason, but here's a duplicate of the sketch used originally in case you want it: https://editor.p5js.org/PotatoBoy/sketches/7NVWhsA7P. |
The issue that I attempted to solve was the same one as before, where resizing of the camera resets the camera. Also, sorry for the late responses and the lack of commits recently. I've been busy. "But nothing happens if you don't call _resize(), so you can't fix the problem about that." |
As for moving the camera, I believe that only the commands affecting the projection matrix turn the camera to type "custom". |
The reason for checking for custom in the previous commit originally was because some people wouldn't care about the camera as you've restated. |
I have understood well that I cannot help you. thank you very much. |
btw @RandomGamingDev I made a little sketch here to test out what it feels like to use a fixed camera distance vs a fixed field of view (what we currently do.) Screen.Recording.2023-10-25.at.6.33.11.PM.movLive: https://editor.p5js.org/davepagurek/sketches/TC3kWHOWk It looks like using a fixed camera distance has some benefits actually? There are less changes when you resize the camera, so that's arguably a plus. And then for our purposes, it means we would only need to update the perspective matrix for default perspective cameras when the window size changes. Here's another quick sketch to verify that if you make a camera, resize the canvas, then click the play button to restart with the camera in that new size, it looks visually the same as it did after starting at a different size + resizing: Screen.Recording.2023-10-25.at.6.39.25.PM.movLive: https://editor.p5js.org/davepagurek/sketches/CTKUAAmMZ |
I'll probably create another pull request to add more complex features like that and just use this pull request to fix the issue with as little as possible and as close to the issue itself. That way other people can more easily chip in and bring up their thoughts on the changes. |
… cameraType and defaults to default
…r automatically reset for cameras of cameraType default when resizing
…alculations for defaultCameraFOV
…ngs() due to a mixup and updated the aspectRatio
Camera test fixes
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 this looks good to go now! Thanks for your patience and the long review process for this one, it ended up being a more complicated issue than we though 😅
…ce-bug Fixed example broken by #6216 and added information for new camera default setting
Created fix for camera settings getting reset each time resizeCanvas() is called
Resolves #6203.
Changes:
Screenshots of the change:
PR Checklist
npm run lint
passes