use codecraft::ecs::Entity;
use codecraft::glam::Vec3;
use codecraft::prelude::*;
use codecraft::sceneobjects::lights::default_lights;
use codecraft::{Light, OrbitCamera, Transform, gizmos, primitives};
struct CubeScene {
cube: Entity,
}
impl CubeScene {
fn new(app: &mut AppState) -> Self {
app.spawn(gizmos::grid());
let [key, rim] = default_lights();
app.spawn_entity((key, Light::object("Key Light")));
app.spawn_entity((rim, Light::object("Rim Light")));
let cube = app.spawn_entity(
primitives::Box::cube(1.0)
.at(0.0, 0.5, 0.0)
.color(Color::srgb(0.9, 0.45, 0.2)),
);
app.spawn_entity(
primitives::Sphere::new(0.4)
.at(1.8, 0.4, -0.6)
.color(Color::srgb(0.3, 0.6, 0.9)),
);
app.spawn_entity((
OrbitCamera::new(Vec3::new(0.0, 0.5, 0.0), 5.0).touchpad(),
OrbitCamera::object("Orbit Camera"),
));
CubeScene { cube }
}
}
impl Scene for CubeScene {
fn update(&mut self, app: &mut AppState) {
let turn = app.time().elapsed * 0.6;
app.edit::<Transform>(self.cube, |transform| transform.set_yaw(turn));
}
}
fn main() {
App::new("cube").scene(CubeScene::new).run();
}