From 64da1ba5779314eee558b0c6f3fb361ac52e47e2 Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Mon, 9 Dec 2024 21:09:21 -0800 Subject: [PATCH] Enable translation along all axes --- app-proto/src/display.rs | 55 +++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/app-proto/src/display.rs b/app-proto/src/display.rs index 184b29e..673985c 100644 --- a/app-proto/src/display.rs +++ b/app-proto/src/display.rs @@ -126,6 +126,10 @@ pub fn Display() -> View { // manipulation let translate_neg_x = create_signal(0.0); let translate_pos_x = create_signal(0.0); + let translate_neg_y = create_signal(0.0); + let translate_pos_y = create_signal(0.0); + let translate_neg_z = create_signal(0.0); + let translate_pos_z = create_signal(0.0); // change listener let scene_changed = create_signal(true); @@ -284,6 +288,10 @@ pub fn Display() -> View { // get the manipulation state let translate_neg_x_val = translate_neg_x.get(); let translate_pos_x_val = translate_pos_x.get(); + let translate_neg_y_val = translate_neg_y.get(); + let translate_pos_y_val = translate_pos_y.get(); + let translate_neg_z_val = translate_neg_z.get(); + let translate_pos_z_val = translate_pos_z.get(); // update the assembly's orientation let ang_vel = { @@ -318,17 +326,21 @@ pub fn Display() -> View { let rep = state.assembly.elements.with_untracked( |elts| elts[sel].representation.get_clone_untracked() ); - let vel_field_x = DMatrix::from_column_slice(5, 5, &[ - 0.0, 0.0, 0.0, 0.0, 1.0, - 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, - 2.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0 - ]); let translate_x = translate_pos_x_val - translate_neg_x_val; - if translate_x != 0.0 { - let vel = translate_x * vel_field_x * rep; - let elt_motion: DVector = time_step * TRANSLATION_SPEED * vel; + let translate_y = translate_pos_y_val - translate_neg_y_val; + let translate_z = translate_pos_z_val - translate_neg_z_val; + if translate_x != 0.0 || translate_y != 0.0 || translate_z != 0.0 { + let vel_field = { + let u = Vector3::new(translate_x, translate_y, translate_z).normalize(); + DMatrix::from_column_slice(5, 5, &[ + 0.0, 0.0, 0.0, 0.0, u[0], + 0.0, 0.0, 0.0, 0.0, u[1], + 0.0, 0.0, 0.0, 0.0, u[2], + 2.0*u[0], 2.0*u[1], 2.0*u[2], 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0 + ]) + }; + let elt_motion: DVector = time_step * TRANSLATION_SPEED * vel_field * rep; assembly_for_raf.deform(vec![(sel, elt_motion.as_view())]); scene_changed.set(true); } @@ -474,9 +486,14 @@ pub fn Display() -> View { let set_manip_signal = move |event: &KeyboardEvent, value: f64| { let mut manipulating = true; + let shift = event.shift_key(); match event.key().as_str() { - "d" => translate_pos_x.set(value), - "a" => translate_neg_x.set(value), + "d" | "D" => translate_pos_x.set(value), + "a" | "A" => translate_neg_x.set(value), + "w" | "W" if shift => translate_neg_z.set(value), + "s" | "S" if shift => translate_pos_z.set(value), + "w" | "W" => translate_pos_y.set(value), + "s" | "S" => translate_neg_y.set(value), _ => manipulating = false }; if manipulating { @@ -495,6 +512,7 @@ pub fn Display() -> View { tabindex="0", on:keydown=move |event: KeyboardEvent| { if event.key() == "Shift" { + // swap navigation inputs roll_cw.set(yaw_right.get()); roll_ccw.set(yaw_left.get()); zoom_in.set(pitch_up.get()); @@ -503,6 +521,12 @@ pub fn Display() -> View { yaw_left.set(0.0); pitch_up.set(0.0); pitch_down.set(0.0); + + // swap manipulation inputs + translate_pos_z.set(translate_neg_y.get()); + translate_neg_z.set(translate_pos_y.get()); + translate_pos_y.set(0.0); + translate_neg_y.set(0.0); } else { if event.key() == "Enter" { /* BENCHMARKING */ turntable.set_fn(|turn| !turn); @@ -514,6 +538,7 @@ pub fn Display() -> View { }, on:keyup=move |event: KeyboardEvent| { if event.key() == "Shift" { + // swap navigation inputs yaw_right.set(roll_cw.get()); yaw_left.set(roll_ccw.get()); pitch_up.set(zoom_in.get()); @@ -522,6 +547,12 @@ pub fn Display() -> View { roll_ccw.set(0.0); zoom_in.set(0.0); zoom_out.set(0.0); + + // swap manipulation inputs + translate_pos_y.set(translate_neg_z.get()); + translate_neg_y.set(translate_pos_z.get()); + translate_pos_z.set(0.0); + translate_neg_z.set(0.0); } else { set_nav_signal(&event, 0.0); set_manip_signal(&event, 0.0);