2023-12-31 18:39:37 -08:00

37 lines
1.1 KiB
Rust

use super::types::TexturedVertex;
// The surface we draw sprites on.
// Every sprite is an instance of this mesh.
//
// These vertices form a rectangle that covers the whole screen.
// Two facts are important to note:
// - This is centered at (0, 0), so scaling doesn't change a sprite's position
// - At scale = 1, this covers the whole screen. Makes scale calculation easier.
//
// Screen coordinates range from -1 to 1, with the origin at the center.
// Texture coordinates range from 0 to 1, with the origin at the top-left
// and (1,1) at the bottom-right.
//
// We can't use the same trick we use for starfield here,
// since each instance of a sprite has multiple vertices.
pub const SPRITE_VERTICES: &[TexturedVertex] = &[
TexturedVertex {
position: [-1.0, 1.0, 0.0],
texture_coords: [0.0, 0.0],
},
TexturedVertex {
position: [1.0, 1.0, 0.0],
texture_coords: [1.0, 0.0],
},
TexturedVertex {
position: [1.0, -1.0, 0.0],
texture_coords: [1.0, 1.0],
},
TexturedVertex {
position: [-1.0, -1.0, 0.0],
texture_coords: [0.0, 1.0],
},
];
pub const SPRITE_INDICES: &[u16] = &[0, 3, 2, 0, 2, 1];