Skip to content

Commit

Permalink
Remove OrthographicProjection.scale (adopted) (bevyengine#15075)
Browse files Browse the repository at this point in the history
# Objective

Hello! I am adopting bevyengine#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 bevyengine#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>
  • Loading branch information
richchurcher and stepancheg authored Sep 9, 2024
1 parent 0cf276f commit f326705
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 23 deletions.
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.
///
/// 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());
}
}
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

0 comments on commit f326705

Please sign in to comment.