fix looking at the cursor kind of?

This commit is contained in:
Viv Lim 2023-09-23 22:21:31 -07:00
parent 959bf44c89
commit d45f7d972f
2 changed files with 45 additions and 41 deletions

View File

@ -68,8 +68,8 @@ fn main() {
.add_system(
systems::mutable_mesh_refresher::mutable_mesh_refresher::<VoxelCursorLayer, BoolVoxel>,
)
// .add_system(move_camera_system)
// .add_system(look_at_cursor_system)
.add_system(move_camera_system)
.add_system(look_at_cursor_system)
.add_system(systems::layer_spawner::layer_spawner)
.add_system(systems::ui::ui_spawner::ui_spawner)
.add_startup_system(setup)
@ -98,7 +98,7 @@ fn setup(
OrbitCameraController::default(),
Vec3::new(-10.0, 21.0, -10.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0), // up ? (guess)
Vec3::new(0.0, 1.0, 0.0), // up ? (guess)
))
.insert(Camera3dBundle::default())
.insert(PropertyPane::new("Camera".to_string(), false));
@ -133,35 +133,35 @@ fn setup(
// &mut materials);
}
// fn move_camera_system(mut cameras: Query<&mut LookTransform>) {
// for mut c in cameras.iter_mut() {
// c.target += Vec3::new(1.0, 1.0, 1.0);
// }
// }
fn move_camera_system(mut cameras: Query<&mut LookTransform>) {
for mut c in cameras.iter_mut() {
c.target += Vec3::new(1.0, 1.0, 1.0);
}
}
// fn look_at_cursor_system(
// mut cameras: Query<&mut LookTransform>,
// cursor_mesh: Query<(&VoxelCursorLayer, &Handle<Mesh>)>,
// ) {
// match cursor_mesh.get_single() {
// Ok((cursor, _cursor_mesh)) => {
// let cursor_pos = into_domain(/*unused?*/ 0, cursor.position.into());
// // assume cursor is a single voxel size
// let cursor_size = into_domain(/*unused?*/ 0, [1, 1, 1]);
fn look_at_cursor_system(
mut cameras: Query<&mut LookTransform>,
cursor_mesh: Query<(&VoxelCursorLayer, &Handle<Mesh>)>,
) {
match cursor_mesh.get_single() {
Ok((cursor, _cursor_mesh)) => {
let cursor_pos = into_domain(/*unused?*/ 0, cursor.position.into());
// assume cursor is a single voxel size
let cursor_size = into_domain(/*unused?*/ 0, [1, 1, 1]);
// // add half the cursor size so that the look target is in the middle of the cursor
// let look_target = cursor_pos + (cursor_size); //((cursor_pos * 2.0) + 1.0) / 2.0;
// add half the cursor size so that the look target is in the middle of the cursor
let look_target = cursor_pos + (cursor_size); //((cursor_pos * 2.0) + 1.0) / 2.0;
// let mut camera = cameras.single_mut();
// camera.target = Vec3 {
// x: look_target.x,
// y: look_target.y,
// z: look_target.z,
// };
// }
// Err(_) => (), // maybe cursor mesh was hidden?
// }
// }
let mut camera = cameras.single_mut();
camera.target = Vec3 {
x: look_target.x,
y: look_target.y,
z: look_target.z,
};
}
Err(_) => (), // maybe cursor mesh was hidden?
}
}
const SAMPLE_WORLD: &[u8] = include_bytes!("../res/sample_level_2.vox");
const SAMPLE_WORLD_OLD: &[u8] = include_bytes!("../res/sample_level_1.vox");

View File

@ -39,7 +39,7 @@ pub fn layer_ui(
TableBuilder::new(ui)
.striped(true)
.scroll(true)
.column(Column::auto().resizable(true))
.column(Column::remainder().resizable(true))
.column(Column::auto().resizable(true))
.header(20.0, |mut header| {
header.col(|ui| {
@ -58,7 +58,7 @@ pub fn layer_ui(
left_named.name.cmp(&right_named.name)
})
{
let (named, entity, mut mutable_mesh, _cursor_layer) = layer_query_result;
let (named, entity, mut mutable_mesh, cursor_layer) = layer_query_result;
body.row(20.0, |mut row| {
row.col(|ui| {
if ui.button(&named.name).clicked()
@ -77,19 +77,23 @@ pub fn layer_ui(
});
});
// if let Some(mut cursor_layer) = cursor_layer {
// ui.horizontal(|ui| {
// if ui.add(egui::DragValue::new(&mut cursor_layer.position.x).speed(1).prefix("x:")).changed() ||
// ui.add(egui::DragValue::new(&mut cursor_layer.position.y).speed(1).prefix("y:")).changed() ||
// ui.add(egui::DragValue::new(&mut cursor_layer.position.z).speed(1).prefix("z:")).changed() {
if let Some(mut cursor_layer) = cursor_layer {
body.row(20.0, |mut row| {
row.col(|ui| {
ui.horizontal(|ui| {
if ui.add(egui::DragValue::new(&mut cursor_layer.position.x).speed(1).prefix("x:")).changed() ||
ui.add(egui::DragValue::new(&mut cursor_layer.position.y).speed(1).prefix("y:")).changed() ||
ui.add(egui::DragValue::new(&mut cursor_layer.position.z).speed(1).prefix("z:")).changed() {
// // invalidate the mesh so it is redrawn
// mutable_mesh.current = false;
// invalidate the mesh so it is redrawn
mutable_mesh.current = false;
// }
// });
}
});
});
});
// }
}
//ui.label(format!("size: {}x{}x{}", layer.size.x, layer.size.y, layer.size.z));
}
});