use codecraft::ecs::Entity;
use codecraft::glam::Vec3;
use codecraft::prelude::*;
use codecraft::{Light, OrbitCamera, Transform, gizmos, primitives};
struct Hello {
cube: Entity,
}
impl Hello {
fn new(app: &mut AppState) -> Self {
app.spawn(gizmos::grid());
app.spawn_entity((
Light::default()
.from(Vec3::new(-0.55, 1.0, -0.45))
.temperature(4200.0)
.strength(2.2)
.angle(1.5),
Light::object("Key Light"),
));
app.spawn_entity((
Light::default()
.from(Vec3::new(1.0, 0.35, 0.1))
.temperature(9500.0)
.strength(1.5)
.angle(0.0)
.shadow(false),
Light::object("Rim Light"),
));
let cube = app.spawn_entity(
primitives::Box::cube(1.0)
.name("Cube")
.color(Color::srgb(0.9, 0.45, 0.2))
.transform(Transform::at(0.0, 0.5, 0.0)),
);
app.spawn_entity(OrbitCamera::new(Vec3::new(0.0, 0.5, 0.0), 5.0));
Hello { cube }
}
}
impl Scene for Hello {
fn update(&mut self, app: &mut AppState) {
let turn = app.time().elapsed * 0.6;
app.edit::<Transform>(self.cube, |transform| transform.set_yaw(turn));
if app.mouse().just_pressed
&& let Some(hit) = app.cursor_ray().plane_hit(0.0)
{
app.edit::<Transform>(self.cube, |transform| {
transform.translation = hit + Vec3::Y * 0.5;
});
}
}
}
fn main() {
App::new("hello").scene(Hello::new).run();
}