From 54e9433731d54e0d8aa87bafd5554d8288afcb96 Mon Sep 17 00:00:00 2001 From: core Date: Fri, 11 Jul 2025 16:37:24 -0400 Subject: [PATCH] feat: proper part rotation take two --- .../assets/config/parts/chassis.part.toml | 8 +++---- .../assets/config/parts/hearty.part.toml | 8 +++---- crates/unified/src/client/parts.rs | 23 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/crates/unified/assets/config/parts/chassis.part.toml b/crates/unified/assets/config/parts/chassis.part.toml index 7b13b92f0546d818767a6036374cbe967bca93bf..bfec3c4151df1b562f197ab641b9954acaed6b6e 100644 --- a/crates/unified/assets/config/parts/chassis.part.toml +++ b/crates/unified/assets/config/parts/chassis.part.toml @@ -10,21 +10,21 @@ mass = 100 [[joints]] id = "Top" -target = { translation = [ 0.0, 50.0, 0.0 ], rotation = 180.0 } +target = { translation = [ 0.0, 50.0, 0.0 ], rotation = 0.0 } snap = { translation = [ 0.0, 25.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Right" -target = { translation = [ 50.0, 0.0, 0.0 ], rotation = 270.0 } +target = { translation = [ 50.0, 0.0, 0.0 ], rotation = -90.0 } snap = { translation = [ 25.0, 0.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Bottom" -target = { translation = [ 0.0, -50.0, 0.0 ], rotation = 0.0 } +target = { translation = [ 0.0, -50.0, 0.0 ], rotation = -180.0 } snap = { translation = [ 0.0, -25.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Left" -target = { translation = [ -50.0, 0.0, 0.0 ], rotation = 90.0 } +target = { translation = [ -50.0, 0.0, 0.0 ], rotation = -270.0 } snap = { translation = [ -25.0, 0.0, 0.0 ], rotation = 0.0 } \ No newline at end of file diff --git a/crates/unified/assets/config/parts/hearty.part.toml b/crates/unified/assets/config/parts/hearty.part.toml index f361efdfb1a8a87f030efb4d60195ff851eb6dc2..c2219bd9a54d3df105819b4ff5c6a98e0dfb081c 100644 --- a/crates/unified/assets/config/parts/hearty.part.toml +++ b/crates/unified/assets/config/parts/hearty.part.toml @@ -14,21 +14,21 @@ exhaust_speed = 250 [[joints]] id = "Top" -target = { translation = [ 0.0, 50.0, 0.0 ], rotation = 180.0 } +target = { translation = [ 0.0, 50.0, 0.0 ], rotation = 0.0 } snap = { translation = [ 0.0, 25.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Right" -target = { translation = [ 50.0, 0.0, 0.0 ], rotation = 270.0 } +target = { translation = [ 50.0, 0.0, 0.0 ], rotation = -90.0 } snap = { translation = [ 25.0, 0.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Bottom" -target = { translation = [ 0.0, -50.0, 0.0 ], rotation = 0.0 } +target = { translation = [ 0.0, -50.0, 0.0 ], rotation = -180.0 } snap = { translation = [ 0.0, -25.0, 0.0 ], rotation = 0.0 } [[joints]] id = "Left" -target = { translation = [ -50.0, 0.0, 0.0 ], rotation = 90.0 } +target = { translation = [ -50.0, 0.0, 0.0 ], rotation = -270.0 } snap = { translation = [ -25.0, 0.0, 0.0 ], rotation = 0.0 } \ No newline at end of file diff --git a/crates/unified/src/client/parts.rs b/crates/unified/src/client/parts.rs index 7db4502121476b5ac9c27be852ec734bbc7c7004..d45038098a1462bfa902eae19cc038d6b051ff79 100644 --- a/crates/unified/src/client/parts.rs +++ b/crates/unified/src/client/parts.rs @@ -186,7 +186,7 @@ fn update_drag_ghosts( // only snap to ourselves - let Ok((parent_position, maybe_me, maybe_parent_ship)) = parts.get(snap_part.0) else { + let Ok((part_being_snapped_to, maybe_me, maybe_parent_ship)) = parts.get(snap_part.0) else { continue; }; @@ -195,7 +195,7 @@ fn update_drag_ghosts( continue; } - let snap_global_translation = parent_position + let snap_global_translation = part_being_snapped_to .mul_transform(*snap_local_transform); let distance_to_cursor = cursor.distance(snap_global_translation.translation().xy()); @@ -221,21 +221,20 @@ fn update_drag_ghosts( continue; }; - let joint_target = parent_position.transform_point(offset.translation); + let joint_target = part_being_snapped_to.transform_point(offset.translation); if debug.0 { gizmos.circle_2d(joint_target.xy(), 3.0, GREEN); } snap = Some(snap_id); - let target_transform = Transform { + let mut target_transform = Transform { translation: joint_target, rotation: ghost.rotation, scale: offset.scale, }; best_distance = distance_to_cursor; - best_target = target_transform; - best_parent_position = Some(parent_position.translation().xy()); + best_parent_position = Some(part_being_snapped_to.translation().xy()); best_snap_position = Some(snap_global_translation); // find, in this particular situation, the best peer on ourselves @@ -246,7 +245,7 @@ fn update_drag_ghosts( let mut best_joint_transform = None; for (our_snap_local_transform, our_snap_joint, our_snap_part, our_snap_id) in &snaps { if Some(our_snap_part.0) != drag.0 { continue; } - let our_snap_global_translation = best_target + let our_snap_global_translation = target_transform .mul_transform(*our_snap_local_transform); let distance = our_snap_global_translation.translation.distance(snap_global_translation.translation()); if distance > best_peer_snap_distance { continue; } @@ -256,18 +255,18 @@ fn update_drag_ghosts( best_peer_snap = Some(our_snap_id); best_peer_snap_distance = distance; best_peer_snap_pos = Some(our_snap_global_translation.translation.xy()); - best_peer_target_pos = Some(best_target.translation.xy()); + best_peer_target_pos = Some(target_transform.translation.xy()); best_joint_transform = Some(our_joint); } - if let Some(our_joint) = best_joint_transform { - best_target.rotation = parent_position.rotation().mul_quat(our_joint.rotation); - } - + target_transform.rotation = part_being_snapped_to.rotation() * (offset.rotation * best_joint_transform.unwrap().rotation.inverse()) * Quat::from_rotation_z(180.0f32.to_radians()); + best_target = target_transform; best_self_snap = best_peer_snap; best_self_snap_position = best_peer_snap_pos; best_self_position = best_peer_target_pos; } + + if debug.0 && let Some(part) = best_parent_position && let Some(snap) = best_snap_position { gizmos.arrow_2d(part, snap.translation().xy(), YELLOW); }