use nightshade_api::prelude::*;
struct State {
target: Entity,
label: Entity,
}
fn main() {
run(
|world| {
set_background(world, Background::Sky);
spawn_floor(world, 20.0);
for index in 0..6 {
let cube = spawn_cube(world, vec3(index as f32 * 2.0 - 5.0, 0.5, -3.0));
set_color(world, cube, [GOLD, TEAL, PURPLE, RED, GREEN, BLUE][index]);
}
let target = spawn_sphere(world, vec3(0.0, 1.0, 0.0));
set_color(world, target, ORANGE);
let focus = position(world, target);
orbit_camera(world, focus, 10.0);
set_orbit_view(world, focus, 10.0, 0.6, 0.4);
set_orbit_zoom(world, true);
let label = spawn_text(world, "1 orbit", ScreenAnchor::TopLeft);
State { target, label }
},
|world, state| {
rotate(world, state.target, Vec3::y(), delta_time(world));
let focus = position(world, state.target);
if key_pressed(world, KeyCode::Digit1) {
orbit_camera(world, focus, 10.0);
set_orbit_focus(world, focus);
set_field_of_view(world, 60.0);
} else if key_pressed(world, KeyCode::Digit2) {
fly_camera(world, vec3(0.0, 4.0, 10.0));
set_perspective(world, 70.0);
} else if key_pressed(world, KeyCode::Digit3) {
first_person(world, vec3(0.0, 1.6, 8.0));
} else if key_pressed(world, KeyCode::Digit4) {
third_person_camera(world, state.target, 6.0);
} else if key_pressed(world, KeyCode::Digit5) {
fixed_camera(world, vec3(8.0, 6.0, 8.0), focus);
look_at(world, vec3(8.0, 6.0, 8.0), focus);
} else if key_pressed(world, KeyCode::Digit6) {
set_orthographic(world, 6.0);
}
let camera = camera_position(world);
let forward = camera_forward(world);
set_text(
world,
state.label,
&format!(
"pos {:.1},{:.1},{:.1} fwd {:.2},{:.2},{:.2}",
camera.x, camera.y, camera.z, forward.x, forward.y, forward.z
),
);
},
)
.unwrap();
}