Skip to content

Commit f326705

Browse files
bas-iestepancheg
andauthored
Remove OrthographicProjection.scale (adopted) (#15075)
# 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 <[email protected]>
1 parent 0cf276f commit f326705

File tree

6 files changed

+10
-23
lines changed

6 files changed

+10
-23
lines changed

crates/bevy_gltf/src/loader.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,8 +1254,7 @@ fn load_node(
12541254
let orthographic_projection = OrthographicProjection {
12551255
near: orthographic.znear(),
12561256
far: orthographic.zfar(),
1257-
scaling_mode: ScalingMode::FixedHorizontal(1.0),
1258-
scale: xmag,
1257+
scaling_mode: ScalingMode::FixedHorizontal(xmag),
12591258
..OrthographicProjection::default_3d()
12601259
};
12611260

crates/bevy_render/src/camera/projection.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,6 @@ pub struct OrthographicProjection {
371371
///
372372
/// Defaults to `ScalingMode::WindowSize(1.0)`
373373
pub scaling_mode: ScalingMode,
374-
/// Scales the projection.
375-
///
376-
/// As scale increases, the apparent size of objects decreases, and vice versa.
377-
///
378-
/// Note: scaling can be set by [`scaling_mode`](Self::scaling_mode) as well.
379-
/// This parameter scales on top of that.
380-
///
381-
/// This property is particularly useful in implementing zoom functionality.
382-
///
383-
/// Defaults to `1.0`.
384-
pub scale: f32,
385374
/// The area that the projection covers relative to `viewport_origin`.
386375
///
387376
/// Bevy's [`camera_system`](crate::camera::camera_system) automatically
@@ -454,10 +443,10 @@ impl CameraProjection for OrthographicProjection {
454443
}
455444

456445
self.area = Rect::new(
457-
self.scale * -origin_x,
458-
self.scale * -origin_y,
459-
self.scale * (projection_width - origin_x),
460-
self.scale * (projection_height - origin_y),
446+
-origin_x,
447+
-origin_y,
448+
projection_width - origin_x,
449+
projection_height - origin_y,
461450
);
462451
}
463452

@@ -505,7 +494,6 @@ impl OrthographicProjection {
505494
/// objects that are behind it.
506495
pub fn default_3d() -> Self {
507496
OrthographicProjection {
508-
scale: 1.0,
509497
near: 0.0,
510498
far: 1000.0,
511499
viewport_origin: Vec2::new(0.5, 0.5),

examples/2d/pixel_grid_snap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use bevy::{
1212
sprite::MaterialMesh2dBundle,
1313
window::WindowResized,
1414
};
15+
use bevy_render::camera::ScalingMode;
1516

1617
/// In-game resolution width.
1718
const RES_WIDTH: u32 = 160;
@@ -176,6 +177,6 @@ fn fit_canvas(
176177
let h_scale = event.width / RES_WIDTH as f32;
177178
let v_scale = event.height / RES_HEIGHT as f32;
178179
let mut projection = projections.single_mut();
179-
projection.scale = 1. / h_scale.min(v_scale).round();
180+
projection.scaling_mode = ScalingMode::WindowSize(h_scale.min(v_scale).round());
180181
}
181182
}

examples/3d/pbr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! This example shows how to configure Physically Based Rendering (PBR) parameters.
22
3+
use bevy::render::camera::ScalingMode;
34
use bevy::{asset::LoadState, prelude::*};
45

56
fn main() {
@@ -120,7 +121,7 @@ fn setup(
120121
Camera3dBundle {
121122
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::default(), Vec3::Y),
122123
projection: OrthographicProjection {
123-
scale: 0.01,
124+
scaling_mode: ScalingMode::WindowSize(100.0),
124125
..OrthographicProjection::default_3d()
125126
}
126127
.into(),

examples/math/custom_primitives.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const TRANSFORM_2D: Transform = Transform {
3636
const PROJECTION_2D: Projection = Projection::Orthographic(OrthographicProjection {
3737
near: -1.0,
3838
far: 10.0,
39-
scale: 1.0,
4039
viewport_origin: Vec2::new(0.5, 0.5),
4140
scaling_mode: ScalingMode::AutoMax {
4241
max_width: 8.0,

examples/stress_tests/many_lights.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ fn setup(
9494
match std::env::args().nth(1).as_deref() {
9595
Some("orthographic") => commands.spawn(Camera3dBundle {
9696
projection: OrthographicProjection {
97-
scale: 20.0,
98-
scaling_mode: ScalingMode::FixedHorizontal(1.0),
97+
scaling_mode: ScalingMode::FixedHorizontal(20.0),
9998
..OrthographicProjection::default_3d()
10099
}
101100
.into(),

0 commit comments

Comments
 (0)