M crates/unified/src/client/starfield.rs => crates/unified/src/client/starfield.rs +14 -9
@@ 184,7 184,7 @@ pub fn resize_starfield(
),
>,
mut resize_event: MessageReader<WindowResized>,
- camera: Single<&Transform, With<MainCamera>>,
+ camera: Single<&Projection, With<MainCamera>>,
) {
for event in resize_event.read() {
let Ok(mut starfield_back) = starfield_back.single_mut() else {
@@ 199,23 199,25 @@ pub fn resize_starfield(
warn!("{:?}: no such entity!", stringify!(starfield_front));
return;
};
+ let Projection::Orthographic(projection) = *camera else {
+ return
+ };
/*if camera.scale.z > 10.0 { // arbitrary
// TODO: find out how to disable sprites // done
} else {
// TODO: find out how to reenable them without toggling on every update :(
}*/
-
starfield_back.custom_size = Some(
- Vec2::new(event.width, event.height) * camera.scale.z
+ Vec2::new(event.width, event.height) * projection.scale
+ Vec2::splat(BACK_STARFIELD_SIZE * 2.0),
);
starfield_mid.custom_size = Some(
- Vec2::new(event.width, event.height) * camera.scale.z
+ Vec2::new(event.width, event.height) * projection.scale
+ Vec2::splat(MID_STARFIELD_SIZE * 2.0),
);
starfield_front.custom_size = Some(
- Vec2::new(event.width, event.height) * camera.scale.z
+ Vec2::new(event.width, event.height) * projection.scale
+ Vec2::splat(FRONT_STARFIELD_SIZE * 2.0),
);
}
@@ 262,7 264,7 @@ pub fn update_starfield(
>,
window: Single<&Window>,
camera: Single<
- &Transform,
+ &Projection,
(
With<MainCamera>,
Without<Me>,
@@ 276,27 278,30 @@ pub fn update_starfield(
let Some(player) = player.iter().next() else {
return;
};
+ let Projection::Orthographic(projection) = *camera else {
+ return
+ };
let mut starfield_back_pos = starfield_back.single_mut().unwrap();
let mut starfield_mid_pos = starfield_mid.single_mut().unwrap();
let mut starfield_front_pos = starfield_front.single_mut().unwrap();
//starfield_pos.translation = (player.translation / STARFIELD_SIZE).round() * STARFIELD_SIZE;
starfield_back_pos.translation = player.translation
+ (-player.translation / 3.0) % BACK_STARFIELD_SIZE
- + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0) * camera.scale.z
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0) * projection.scale
/ 2.0)
% BACK_STARFIELD_SIZE
+ Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 5.0);
starfield_mid_pos.translation = player.translation
+ (-player.translation / 2.5) % MID_STARFIELD_SIZE
- + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0) * camera.scale.z
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0) * projection.scale
/ 2.0)
% MID_STARFIELD_SIZE
+ Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0)
- Vec3::new(0.0, 0.0, 4.5);
starfield_front_pos.translation = player.translation
+ (-player.translation / 2.0) % FRONT_STARFIELD_SIZE
- + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0) * camera.scale.z
+ + (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0) * projection.scale
/ 2.0)
% FRONT_STARFIELD_SIZE
+ Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0)
M crates/unified/src/client/zoom.rs => crates/unified/src/client/zoom.rs +13 -11
@@ 65,7 65,7 @@ fn on_scroll(
),
>,
mut camera: Single<
- (&mut Camera, &mut Transform),
+ (&mut Camera, &mut Transform, &mut Projection),
(
With<MainCamera>,
Without<OrbitCamera>,
@@ 92,18 92,19 @@ fn on_scroll(
let (mut starfield_mid, mut starfield_mid_pos, mut visibility_mid, size_mid) = starfield_mid.into_inner();
let (mut starfield_front, mut starfield_front_pos, mut visibility_front, size_front) =
starfield_front.into_inner();
+ let Projection::Orthographic(ref mut camera_projection) = camera.2.clone() else { return };
for event in scroll_events.read() {
match event.unit {
MouseScrollUnit::Line | MouseScrollUnit::Pixel => {
if event.y > 0.0 {
- camera.1.scale *= 0.97;
+ camera_projection.scale *= 0.97;
starguide_camera.1.scale *= 0.97;
} else {
- camera.1.scale *= 1.03;
+ camera_projection.scale *= 1.03;
starguide_camera.1.scale *= 1.03;
}
- if camera.1.scale.z > 20.0 && matches!(gameplay_state.get(), GameplayState::Main) {
+ if camera_projection.scale > 20.0 && matches!(gameplay_state.get(), GameplayState::Main) {
camera.0.is_active = false;
starguide_camera.0.is_active = true;
orbit_camera.is_active = true;
@@ 117,7 118,7 @@ fn on_scroll(
*visibility_back = Visibility::Hidden;
*visibility_mid = Visibility::Hidden;
*visibility_front = Visibility::Hidden;
- } else if camera.1.scale.z <= 20.0 && matches!(gameplay_state.get(), GameplayState::Starguide) {
+ } else if camera_projection.scale <= 20.0 && matches!(gameplay_state.get(), GameplayState::Starguide) {
camera.0.is_active = true;
gameplay_next_state.set(GameplayState::Main);
starguide_camera.0.is_active = false;
@@ 151,15 152,15 @@ fn on_scroll(
*visibility_front = Visibility::Inherited;
}
starfield_back.custom_size =
- Some(window.size() * camera.1.scale.z + Vec2::splat(BACK_STARFIELD_SIZE * 2.0));
+ Some(window.size() * camera_projection.scale + Vec2::splat(BACK_STARFIELD_SIZE * 2.0));
starfield_mid.custom_size =
- Some(window.size() * camera.1.scale.z + Vec2::splat(MID_STARFIELD_SIZE * 2.0));
+ Some(window.size() * camera_projection.scale + Vec2::splat(MID_STARFIELD_SIZE * 2.0));
starfield_front.custom_size =
- Some(window.size() * camera.1.scale.z + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0));
+ Some(window.size() * camera_projection.scale + Vec2::splat(FRONT_STARFIELD_SIZE * 2.0));
starfield_back_pos.translation = player.translation
+ (-player.translation / 3.0) % BACK_STARFIELD_SIZE
+ (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)
- * camera.1.scale.z
+ * camera_projection.scale
/ 2.0)
% BACK_STARFIELD_SIZE
+ Vec3::new(0.0, BACK_STARFIELD_SIZE, 0.0)
@@ 167,7 168,7 @@ fn on_scroll(
starfield_mid_pos.translation = player.translation
+ (-player.translation / 2.5) % MID_STARFIELD_SIZE
+ (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)
- * camera.1.scale.z
+ * camera_projection.scale
/ 2.0)
% MID_STARFIELD_SIZE
+ Vec3::new(0.0, MID_STARFIELD_SIZE, 0.0)
@@ 175,7 176,7 @@ fn on_scroll(
starfield_front_pos.translation = player.translation
+ (-player.translation / 2.0) % FRONT_STARFIELD_SIZE
+ (Vec3::new(window.resolution.width(), -window.resolution.height(), 0.0)
- * camera.1.scale.z
+ * camera_projection.scale
/ 2.0)
% FRONT_STARFIELD_SIZE
+ Vec3::new(0.0, FRONT_STARFIELD_SIZE, 0.0)
@@ 183,4 184,5 @@ fn on_scroll(
}
}
}
+ *camera.2 = Projection::Orthographic(camera_projection.clone());
}