Skip to content
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

Add a function that returns a Camera2D of the default camera mode; Give Camera::default a quick documentation note #881

Open
lshoyfer opened this issue Jan 12, 2025 · 0 comments

Comments

@lshoyfer
Copy link

Currently Camera::default() gives a barebones camera with no relation to set_default_camera()'s "Reset default 2D camera mode" behavior, which I believe mostly revolves around the pixel_perfect_projection_matrix() function in lib.rs as it's the None case of projection_matrix().

macroquad/src/lib.rs

Lines 446 to 461 in 2f7f3c8

pub(crate) fn pixel_perfect_projection_matrix(&self) -> glam::Mat4 {
let (width, height) = miniquad::window::screen_size();
let dpi = miniquad::window::dpi_scale();
glam::Mat4::orthographic_rh_gl(0., width / dpi, height / dpi, 0., -1., 1.)
}
pub(crate) fn projection_matrix(&self) -> glam::Mat4 {
if let Some(matrix) = self.camera_matrix {
matrix
} else {
self.pixel_perfect_projection_matrix()
}
}

I ran into Camera::default() when I wanted to get around set_default_camera() not changing the viewport back to (0., 0. buffer_width, buffer_height) if a previous camera changed the context's viewport (which was going to be my original issue to post but I noticed a recent commit fixing this which is great) by using set_camera with aCamera2D equivalent to the default camera mode. That is currently what I do manually, but perhaps some clarifying documentation on Camera::default()'s role could be useful to people to avoid a quick mix-up, as well as a function that returns a Camera2D that when passed to set_camera() mirrors set_default_camera()'s behavior (assuming the viewport fix is in place).

I can see such a function being useful for avoiding some boilerplate on the user's part to allow better fine-tuning and interchanging between certain UI drawing, letterboxing, and player drawing setups. Implementing this function could also be done by rearranging some of the inner logic and returning the Camera2D as an easy convenience but I think the current pixel_perfect_projection_matrix() implementation is intentionally more efficient, so I'm not suggesting that, but rather to offer the function as an extra computational convenience. I also wouldn't pass this on to Camera::default(), as I think its role as a barebones slate is intentional as well and fits in with idiom.

As it stands with the viewport fix committed, set_default_camera() is fine enough on its own if anything but perhaps Camera::default() deserves some quick documentation at least for clarity that it is unrelated to set_default_camera() and has a different meaning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant