Added correct zoom parallax

master
Mark 2023-12-24 12:01:03 -08:00
parent c29d5f520d
commit babd410182
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 14 additions and 8 deletions

View File

@ -16,18 +16,23 @@ mod render;
mod ship; mod ship;
mod system; mod system;
pub const ZOOM_MIN: Pfloat = 200.0;
pub const ZOOM_MAX: Pfloat = 2000.0;
// Z-axis range for starfield stars // Z-axis range for starfield stars
pub const STARFIELD_PARALLAX_MIN: f32 = 100.0; pub const STARFIELD_PARALLAX_MIN: f32 = 100.0;
pub const STARFIELD_PARALLAX_MAX: f32 = 200.0; pub const STARFIELD_PARALLAX_MAX: f32 = 200.0;
// Number of stars in one starfield tile
pub const STARFIELD_COUNT: u64 = 100;
// Size of a square starfield tile, in game units. // Size of a square starfield tile, in game units.
// A tile of size PARALLAX_MAX * screen-size-in-game-units // A tile of size PARALLAX_MAX * screen-size-in-game-units
// will completely cover a (square) screen. This depends on zoom! // will completely cover a (square) screen. This depends on zoom!
pub const STARFIELD_SIZE: u64 = STARFIELD_PARALLAX_MAX as u64 * 500; //
// Use a value smaller than zoom_max for debug.
pub const ZOOM_MIN: Pfloat = 200.0; pub const STARFIELD_SIZE: u64 = STARFIELD_PARALLAX_MAX as u64 * ZOOM_MAX as u64;
pub const ZOOM_MAX: Pfloat = 2000.0; // Average number of stars per game unit
pub const STARFIELD_DENSITY: f64 = 0.01;
// Number of stars in one starfield tile
// Must fit inside an i32
pub const STARFIELD_COUNT: u64 = (STARFIELD_SIZE as f64 * STARFIELD_DENSITY) as u64;
use crate::{ use crate::{
doodad::Doodad, doodad::Doodad,

View File

@ -5,7 +5,7 @@ use std::{iter, rc::Rc};
use wgpu; use wgpu;
use winit::{self, dpi::PhysicalSize, window::Window}; use winit::{self, dpi::PhysicalSize, window::Window};
use crate::{Game, STARFIELD_COUNT, STARFIELD_PARALLAX_MIN, STARFIELD_SIZE, ZOOM_MAX}; use crate::{Game, STARFIELD_COUNT, STARFIELD_PARALLAX_MIN, STARFIELD_SIZE, ZOOM_MAX, ZOOM_MIN};
use super::{ use super::{
globaldata::{GlobalData, GlobalDataContent}, globaldata::{GlobalData, GlobalDataContent},
@ -217,7 +217,8 @@ impl GPUState {
for s in game.sprites() { for s in game.sprites() {
// Parallax is computed here, so we can check if this sprite is visible. // Parallax is computed here, so we can check if this sprite is visible.
let pos = (s.pos - game.camera.pos.to_vec()) / s.parallax; let pos =
(s.pos - game.camera.pos.to_vec()) / (s.parallax + game.camera.zoom / ZOOM_MIN);
let texture = self.texture_array.get_texture(&s.name[..]); let texture = self.texture_array.get_texture(&s.name[..]);
// Game dimensions of this sprite post-scale. // Game dimensions of this sprite post-scale.