diff --git a/src/doodad.rs b/src/doodad.rs index f949c66..e5dabc0 100644 --- a/src/doodad.rs +++ b/src/doodad.rs @@ -6,6 +6,7 @@ pub struct Doodad { pub sprite: String, pub pos: Point2, pub parallax: Pfloat, + pub height: Pfloat, } impl Spriteable for Doodad { @@ -15,6 +16,7 @@ impl Spriteable for Doodad { name: self.sprite.clone(), angle: Deg { 0: 0.0 }, scale: 1.0, + height: self.height, parallax: self.parallax, }; } diff --git a/src/main.rs b/src/main.rs index 8c36faa..4589467 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,11 +27,11 @@ use crate::{ #[derive(Debug, Clone, Copy)] struct Camera { - // Camera center + /// Camera center pos: Point2, - // Camera zoom - // (How many game units tall is the viewport?) + /// Camera zoom + /// (How many game units tall is the viewport?) zoom: Pfloat, } @@ -40,29 +40,35 @@ trait Spriteable { } struct Sprite { - // Name of the sprite to draw + /// Name of the sprite to draw name: String, - // This object's position, in world coordinates. + /// This object's position, in world coordinates. pos: Point2, + /// The size of this sprite, + /// given as height in world units. + height: Pfloat, + + /// Scale factor. + /// if this is 1, sprite height is exactly self.height. scale: Pfloat, - // This sprite's rotation - // (relative to north, measured ccw) + /// This sprite's rotation + /// (relative to north, measured ccw) angle: Deg, - // Parallax factor. - // More positive => farther away - // More negative => closer - // Zero: no parallax. + /// Parallax factor. + /// More positive => farther away + /// More negative => closer + /// Zero: no parallax. parallax: Pfloat, } impl Sprite { const PARALLAX_STRENGTH: Pfloat = 0.1; - // Returns post-parallax position in game coordinates. + /// Returns post-parallax position in game coordinates. pub fn post_parallax_position(&self, camera: Camera) -> Point2 { let v = camera.pos.to_vec() - self.pos.to_vec(); return self.pos + (v * self.parallax * Self::PARALLAX_STRENGTH); diff --git a/src/render/gpustate.rs b/src/render/gpustate.rs index c5e3b1a..e94da15 100644 --- a/src/render/gpustate.rs +++ b/src/render/gpustate.rs @@ -269,7 +269,7 @@ impl GPUState { // but we omit the division. // This gives us a small margin, and lets us re-use the value // without an extra multiply. - let height = texture.height * s.scale; + let height = s.height * s.scale; let width = height * texture.aspect; // Don't draw (or compute matrices for) diff --git a/src/render/texturearray.rs b/src/render/texturearray.rs index da70c1c..904d0d8 100644 --- a/src/render/texturearray.rs +++ b/src/render/texturearray.rs @@ -16,7 +16,6 @@ pub struct TextureArray { pub struct Texture { pub index: u32, // Index in texture array pub aspect: f32, // width / height - pub height: f32, // Height in game units } #[derive(Deserialize)] @@ -29,7 +28,6 @@ struct Textures { struct Tex { name: String, path: String, - height: f32, } impl Tex { @@ -68,7 +66,6 @@ impl TextureArray { let raw = texture_index.error.read(device, queue)?; let error_texture = Texture { index: 0, - height: texture_index.error.height, aspect: raw.dimensions.0 as f32 / raw.dimensions.1 as f32, }; texture_data.push(raw); @@ -79,7 +76,6 @@ impl TextureArray { let raw = t.read(device, queue)?; let tx = Texture { index: i, - height: t.height, aspect: raw.dimensions.0 as f32 / raw.dimensions.1 as f32, }; textures.insert(t.name.clone(), tx); diff --git a/src/ship.rs b/src/ship.rs index 3a1bf78..01ba18a 100644 --- a/src/ship.rs +++ b/src/ship.rs @@ -12,6 +12,12 @@ impl ShipKind { Self::Gypsum => "gypsum", } } + + fn height(&self) -> Pfloat { + match self { + Self::Gypsum => 100.0, + } + } } pub struct Ship { @@ -36,6 +42,7 @@ impl Spriteable for Ship { angle: self.body.angle, scale: 1.0, parallax: 0.0, + height: self.kind.height(), }; } } diff --git a/src/system.rs b/src/system.rs index 5344a53..37303bf 100644 --- a/src/system.rs +++ b/src/system.rs @@ -13,6 +13,7 @@ impl System { pos: (0.0, 0.0).into(), sprite: "a0".to_owned(), parallax: 3.0, + height: 80.0, }); s.bodies.push(Doodad { @@ -24,6 +25,7 @@ impl System { .to_cartesian(), sprite: "earth".to_owned(), parallax: 1.0, + height: 120.0, }); s.bodies.push(Doodad { @@ -35,6 +37,7 @@ impl System { .to_cartesian(), sprite: "small".to_owned(), parallax: -1.0, + height: 50.0, }); return s;