use spottedcat::{Context, Spot, Model, Image, DrawOption3D, WindowConfig};
use std::time::Duration;
struct ModelTest {
cube: Model,
rotation: f32,
}
impl Spot for ModelTest {
fn initialize(_context: &mut Context) -> Self {
let rgba = vec![
255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 0, 255, ];
let texture = Image::new_from_rgba8(2.into(), 2.into(), &rgba).unwrap();
let cube = Model::cube(1.0).unwrap()
.with_material(texture);
Self {
cube,
rotation: 0.0,
}
}
fn update(&mut self, _context: &mut Context, dt: Duration) {
self.rotation += dt.as_secs_f32();
}
fn draw(&mut self, context: &mut Context) {
let opts = DrawOption3D::default()
.with_position([0.0, 0.0, 0.0])
.with_rotation([self.rotation, self.rotation * 0.5, 0.0]);
self.cube.draw(context, opts);
}
fn remove(&self) {}
}
fn main() {
spottedcat::run::<ModelTest>(WindowConfig {
title: "3D Model Test".to_string(),
..Default::default()
});
}