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

Remove OrthographicProjection.scale (adopted) #15075

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,8 +1254,7 @@ fn load_node(
let orthographic_projection = OrthographicProjection {
near: orthographic.znear(),
far: orthographic.zfar(),
scaling_mode: ScalingMode::FixedHorizontal(1.0),
scale: xmag,
scaling_mode: ScalingMode::FixedHorizontal(xmag),
..OrthographicProjection::default_3d()
};

Expand Down
20 changes: 4 additions & 16 deletions crates/bevy_render/src/camera/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,6 @@ pub struct OrthographicProjection {
///
/// Defaults to `ScalingMode::WindowSize(1.0)`
pub scaling_mode: ScalingMode,
/// Scales the projection.
///
/// As scale increases, the apparent size of objects decreases, and vice versa.
///
/// Note: scaling can be set by [`scaling_mode`](Self::scaling_mode) as well.
/// This parameter scales on top of that.
Comment on lines -378 to -379
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it pretty easy to scale multiple variants of ScalingMode since you can just modify a single f32. Are we at all concerned about hurting ergonomics?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not particularly; projects will only need to handle this once, and the majority of projects will have a single scaling mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also run into a few people now who miss the existence of ScalingMode because of scale, leading them to ask questions. In this way, I think it's hurting them by not just making them think up front about how the camera should be configured.

///
/// This property is particularly useful in implementing zoom functionality.
///
/// Defaults to `1.0`.
pub scale: f32,
/// The area that the projection covers relative to `viewport_origin`.
///
/// Bevy's [`camera_system`](crate::camera::camera_system) automatically
Expand Down Expand Up @@ -454,10 +443,10 @@ impl CameraProjection for OrthographicProjection {
}

self.area = Rect::new(
self.scale * -origin_x,
self.scale * -origin_y,
self.scale * (projection_width - origin_x),
self.scale * (projection_height - origin_y),
-origin_x,
-origin_y,
projection_width - origin_x,
projection_height - origin_y,
);
}

Expand Down Expand Up @@ -505,7 +494,6 @@ impl OrthographicProjection {
/// objects that are behind it.
pub fn default_3d() -> Self {
OrthographicProjection {
scale: 1.0,
near: 0.0,
far: 1000.0,
viewport_origin: Vec2::new(0.5, 0.5),
Expand Down
3 changes: 2 additions & 1 deletion examples/2d/pixel_grid_snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use bevy::{
sprite::MaterialMesh2dBundle,
window::WindowResized,
};
use bevy_render::camera::ScalingMode;

/// In-game resolution width.
const RES_WIDTH: u32 = 160;
Expand Down Expand Up @@ -176,6 +177,6 @@ fn fit_canvas(
let h_scale = event.width / RES_WIDTH as f32;
let v_scale = event.height / RES_HEIGHT as f32;
let mut projection = projections.single_mut();
projection.scale = 1. / h_scale.min(v_scale).round();
projection.scaling_mode = ScalingMode::WindowSize(h_scale.min(v_scale).round());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this appears to produce the same behaviour as the existing example, though if there's a simpler method I haven't seen that's great too!

}
}
3 changes: 2 additions & 1 deletion examples/3d/pbr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! This example shows how to configure Physically Based Rendering (PBR) parameters.

use bevy::render::camera::ScalingMode;
use bevy::{asset::LoadState, prelude::*};

fn main() {
Expand Down Expand Up @@ -120,7 +121,7 @@ fn setup(
Camera3dBundle {
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::default(), Vec3::Y),
projection: OrthographicProjection {
scale: 0.01,
scaling_mode: ScalingMode::WindowSize(100.0),
..OrthographicProjection::default_3d()
}
.into(),
Expand Down
1 change: 0 additions & 1 deletion examples/math/custom_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const TRANSFORM_2D: Transform = Transform {
const PROJECTION_2D: Projection = Projection::Orthographic(OrthographicProjection {
near: -1.0,
far: 10.0,
scale: 1.0,
viewport_origin: Vec2::new(0.5, 0.5),
scaling_mode: ScalingMode::AutoMax {
max_width: 8.0,
Expand Down
3 changes: 1 addition & 2 deletions examples/stress_tests/many_lights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ fn setup(
match std::env::args().nth(1).as_deref() {
Some("orthographic") => commands.spawn(Camera3dBundle {
projection: OrthographicProjection {
scale: 20.0,
scaling_mode: ScalingMode::FixedHorizontal(1.0),
scaling_mode: ScalingMode::FixedHorizontal(20.0),
..OrthographicProjection::default_3d()
}
.into(),
Expand Down