-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 example demonstrating how to zoom orthographic cameras #2580
Comments
I think this should also note that if the scale is less than one then you may have to modify the |
@alice-i-cecile I also think zoom for fn zoom_3d_system(
mut whl: EventReader<MouseWheel>,
mut query: Query<(&mut Camera, &mut PerspectiveProjection)>,
windows: Res<Windows>,
){
let delta_zoom: f32 = whl.iter().map(|e| e.y).sum();
if delta_zoom == 0. {
return;
}
let prim = windows.get_primary().unwrap();
for (mut camera, mut project) in query.iter_mut() {
project.fov = (project.fov - delta_zoom * 0.01).abs();
//Calculate projection with new fov
project.update(prim.width(), prim.height());
//Update camera with the new fov
camera.projection_matrix = project.get_projection_matrix();
camera.depth_calculation = project.depth_calculation();
println!("FOV: {:?}", project.fov);
}
} |
I might take a crack at this one. I'm aware of related PR #11022 and will adopt that if the author doesn't clear the conflicts. |
Hrm. Quite a bit has changed in |
I notice that in 2024 I'm able to happily scroll without needing to modify the transform at all, take into account mouse position etc. Am I missing something? For example, this seems to work fine: fn camera_controls(
mut camera: Query<&mut Projection, With<Camera>>,
mut mouse_wheel_input: EventReader<MouseWheel>,
) {
let delta_zoom: f32 = mouse_wheel_input.read().map(|e| e.y).sum();
if delta_zoom == 0. {
return;
}
let mut projection = camera.single_mut();
if let Projection::Orthographic(cam) = &mut *projection {
let ScalingMode::FixedVertical(current) = cam.scaling_mode else {
return;
};
let zoom_level = (current + CAMERA_ZOOM_SPEED * delta_zoom)
.clamp(CAMERA_ZOOM_RANGE.start, CAMERA_ZOOM_RANGE.end);
cam.scaling_mode = ScalingMode::FixedVertical(zoom_level);
}
} |
Quick demo: https://youtu.be/OVUyaQ0a8Ss |
If we didn't need to clamp, we could just cam.scaling_mode *= CAMERA_ZOOM_SPEED * delta_zoom; and be done with it. |
# Objective Add examples for zooming (and orbiting) orthographic and perspective cameras. I'm pretty green with 3D, so please treat with suspicion! I note that if/when #15075 is merged, `.scale` will go away so this example uses `.scaling_mode`. Closes #2580 --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Jan Hohenheim <jan@hohenheim.ch>
# Objective Hello! I am adopting #11022 to resolve conflicts with `main`. tldr: this removes `scale` in favour of `scaling_mode`. Please see the original PR for explanation/discussion. Also relates to #2580. ## Migration Guide Replace all uses of `scale` with `scaling_mode`, keeping in mind that `scale` is (was) a multiplier. For example, replace ```rust scale: 2.0, scaling_mode: ScalingMode::FixedHorizontal(4.0), ``` with ```rust scaling_mode: ScalingMode::FixedHorizontal(8.0), ``` --------- Co-authored-by: Stepan Koltsov <stepan.koltsov@gmail.com>
How can Bevy's documentation be improved?
Zooming an orthographic camera is surprisingly tricky; unlike ordinary cameras moving them further away from the object doesn't cause the size of the objects displayed to change as all their projection is parallel.
@TheRawMeatball provided this initial solution in #help:
This should be straightforward to verify and clean up. Adding panning or rotation might also be worth including in the same example.
The text was updated successfully, but these errors were encountered: