diff --git a/src/game/ship.rs b/src/game/ship.rs index f76adba..390f2f8 100644 --- a/src/game/ship.rs +++ b/src/game/ship.rs @@ -3,9 +3,7 @@ use cgmath::{Deg, Point2, Point3}; use crate::{ content::{self, ship::Engine}, physics::PhysicsBody, - render::Sprite, - render::SpriteTexture, - render::Spriteable, + render::{Sprite, SpriteTexture, Spriteable, SubSprite}, }; pub struct Ship { @@ -35,7 +33,7 @@ impl Spriteable for Ship { Some( self.engines .iter() - .map(|e| Sprite { + .map(|e| SubSprite { pos: Point3 { x: e.pos.x, y: e.pos.y, @@ -44,7 +42,6 @@ impl Spriteable for Ship { texture: SpriteTexture("flare::ion".to_owned()), angle: Deg(0.0), size: e.size, - children: None, }) .collect(), ) diff --git a/src/render/gpustate.rs b/src/render/gpustate.rs index d298b8c..9fa132e 100644 --- a/src/render/gpustate.rs +++ b/src/render/gpustate.rs @@ -9,6 +9,7 @@ use super::{ consts::{OPENGL_TO_WGPU_MATRIX, SPRITE_INSTANCE_LIMIT, STARFIELD_INSTANCE_LIMIT}, globaldata::{GlobalData, GlobalDataContent}, pipeline::PipelineBuilder, + sprite::SubSprite, texturearray::TextureArray, vertexbuffer::{ consts::{SPRITE_INDICES, SPRITE_VERTICES}, @@ -285,15 +286,10 @@ impl GPUState { &self, game: &Game, instances: &mut Vec, - s: Sprite, + s: SubSprite, parent_pos: Point2, parent_angle: Deg, ) { - // TODO: clean up - if s.children.is_some() { - panic!("Child sprites must not have child sprites!") - } - let texture = self.texture_array.get_sprite_texture(s.texture); let scale = s.size / (s.pos.z * game.camera.zoom); let sprite_aspect_and_scale = diff --git a/src/render/mod.rs b/src/render/mod.rs index 445ba36..f7993a6 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -7,7 +7,7 @@ mod texturearray; mod vertexbuffer; pub use gpustate::GPUState; -pub use sprite::{Sprite, Spriteable}; +pub use sprite::{Sprite, Spriteable, SubSprite}; /// A handle to a sprite texture #[derive(Debug, Clone)] diff --git a/src/render/sprite.rs b/src/render/sprite.rs index 3a85248..6323aca 100644 --- a/src/render/sprite.rs +++ b/src/render/sprite.rs @@ -3,7 +3,7 @@ use cgmath::{Deg, Point3}; use super::SpriteTexture; pub struct Sprite { - /// Name of the sprite to draw + /// The sprite texture to draw pub texture: SpriteTexture, /// This object's position, in world coordinates. @@ -18,13 +18,26 @@ pub struct Sprite { pub angle: Deg, /// Sprites that should be drawn relative to this sprite. - /// Coordinates of sprites in this array will be interpreted - /// as world units, relative to the center of this sprite, - /// before any rotation or scaling. - /// Children rotate with their parent sprite. - /// - /// Note that child sprites may NOT have children. - pub children: Option>, + pub children: Option>, +} + +pub struct SubSprite { + /// The sprite texture to draw + pub texture: SpriteTexture, + + /// This object's position, in world coordinates. + /// This is relative to this sprite's parent. + pub pos: Point3, + + /// The size of this sprite, + /// given as height in world units. + pub size: f32, + + /// This sprite's rotation + /// (relative to north, measured ccw) + /// Just as position, this is relative to this + /// subsprite's parent sprite. + pub angle: Deg, } pub trait Spriteable {