use crate::kv6::Kv6;
pub const SPRITE_FLAG_NO_SHADING: u32 = 1 << 0;
pub const SPRITE_FLAG_KFA: u32 = 1 << 1;
pub const SPRITE_FLAG_INVISIBLE: u32 = 1 << 2;
pub const SPRITE_FLAG_NO_Z: u32 = 1 << 3;
#[derive(Debug, Clone)]
pub struct Sprite {
pub kv6: Kv6,
pub p: [f32; 3],
pub s: [f32; 3],
pub h: [f32; 3],
pub f: [f32; 3],
pub flags: u32,
pub material: u8,
pub alpha_mul: u8,
pub material_map: Vec<(u32, u8)>,
}
impl Sprite {
#[must_use]
pub fn axis_aligned(kv6: Kv6, pos: [f32; 3]) -> Self {
Self {
kv6,
p: pos,
s: [1.0, 0.0, 0.0],
h: [0.0, 1.0, 0.0],
f: [0.0, 0.0, 1.0],
flags: 0,
material: 0,
alpha_mul: 255,
material_map: Vec::new(),
}
}
pub fn carve_sphere_with_colfunc<S, C>(
&mut self,
centre: [i32; 3],
radius: u32,
solid: S,
colfunc: C,
) where
S: Fn(i32, i32, i32) -> bool,
C: Fn(i32, i32, i32) -> u32,
{
self.kv6
.carve_sphere_with_colfunc(centre, radius, solid, colfunc);
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn carve_sphere_delegates_to_kv6_and_leaves_pose() {
const BASE: u32 = 0x8033_4455;
let kv6 = Kv6::from_fn_shaded(16, 16, 16, |_, _, _| Some(BASE));
let mut sprite = Sprite::axis_aligned(kv6, [10.0, 20.0, 30.0]);
let before = sprite.kv6.voxels.len();
sprite.carve_sphere_with_colfunc([8, 8, 8], 4, |_, _, _| true, |_, _, _| 0x8000_FF00);
assert_ne!(sprite.kv6.voxels.len(), before);
assert_eq!(sprite.p, [10.0, 20.0, 30.0]);
assert_eq!(sprite.s, [1.0, 0.0, 0.0]);
}
}