Added correct zoom parallax
parent
c29d5f520d
commit
babd410182
17
src/main.rs
17
src/main.rs
|
@ -16,18 +16,23 @@ mod render;
|
|||
mod ship;
|
||||
mod system;
|
||||
|
||||
pub const ZOOM_MIN: Pfloat = 200.0;
|
||||
pub const ZOOM_MAX: Pfloat = 2000.0;
|
||||
|
||||
// Z-axis range for starfield stars
|
||||
pub const STARFIELD_PARALLAX_MIN: f32 = 100.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.
|
||||
// A tile of size PARALLAX_MAX * screen-size-in-game-units
|
||||
// will completely cover a (square) screen. This depends on zoom!
|
||||
pub const STARFIELD_SIZE: u64 = STARFIELD_PARALLAX_MAX as u64 * 500;
|
||||
|
||||
pub const ZOOM_MIN: Pfloat = 200.0;
|
||||
pub const ZOOM_MAX: Pfloat = 2000.0;
|
||||
//
|
||||
// Use a value smaller than zoom_max for debug.
|
||||
pub const STARFIELD_SIZE: u64 = STARFIELD_PARALLAX_MAX as u64 * ZOOM_MAX as u64;
|
||||
// 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::{
|
||||
doodad::Doodad,
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{iter, rc::Rc};
|
|||
use wgpu;
|
||||
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::{
|
||||
globaldata::{GlobalData, GlobalDataContent},
|
||||
|
@ -217,7 +217,8 @@ impl GPUState {
|
|||
|
||||
for s in game.sprites() {
|
||||
// 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[..]);
|
||||
|
||||
// Game dimensions of this sprite post-scale.
|
||||
|
|
Loading…
Reference in New Issue