Skip to content

Commit

Permalink
Small optimizations to rotation and translation
Browse files Browse the repository at this point in the history
  • Loading branch information
urholaukkarinen committed Nov 5, 2021
1 parent 617ead8 commit 9fe5ac2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ pub(crate) fn update_rotation(subgizmo: &SubGizmo, ui: &Ui, _ray: Ray) -> Option
state.current_delta += angle_delta;
});

let (scale, mut rotation, translation) = config.model_matrix.to_scale_rotation_translation();
rotation = Quat::from_axis_angle(subgizmo.normal(), -angle_delta) * rotation;
let rotation =
Quat::from_axis_angle(subgizmo.normal(), -angle_delta) * subgizmo.config.rotation;

Some(GizmoResult {
transform: Mat4::from_scale_rotation_translation(scale, rotation, translation)
.to_cols_array_2d(),
transform: Mat4::from_scale_rotation_translation(
subgizmo.config.scale,
rotation,
subgizmo.config.translation,
)
.to_cols_array_2d(),
mode: GizmoMode::Rotate,
value: (subgizmo.normal() * state.current_delta).to_array(),
})
Expand Down
24 changes: 12 additions & 12 deletions src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ pub(crate) fn update_translation(subgizmo: &SubGizmo, ui: &Ui, ray: Ray) -> Opti
new_point = state.start_point + new_delta;
}

let (scale, rotation, mut translation) =
subgizmo.config.model_matrix.to_scale_rotation_translation();
translation += new_point - state.last_point;

subgizmo.update_state_with(ui, |state: &mut TranslationState| {
state.last_point = new_point;
state.current_delta = new_delta;
});

Some(GizmoResult {
transform: Mat4::from_scale_rotation_translation(scale, rotation, translation)
.to_cols_array_2d(),
transform: Mat4::from_scale_rotation_translation(
subgizmo.config.scale,
subgizmo.config.rotation,
subgizmo.config.translation + new_point - state.last_point,
)
.to_cols_array_2d(),
mode: GizmoMode::Translate,
value: state.current_delta.to_array(),
})
Expand Down Expand Up @@ -187,18 +187,18 @@ pub(crate) fn update_translation_plane(
new_point = state.start_point + new_delta;
}

let (scale, rotation, mut translation) =
subgizmo.config.model_matrix.to_scale_rotation_translation();
translation += new_point - state.last_point;

subgizmo.update_state_with(ui, |state: &mut TranslationState| {
state.last_point = new_point;
state.current_delta = new_delta;
});

Some(GizmoResult {
transform: Mat4::from_scale_rotation_translation(scale, rotation, translation)
.to_cols_array_2d(),
transform: Mat4::from_scale_rotation_translation(
subgizmo.config.scale,
subgizmo.config.rotation,
subgizmo.config.translation + new_point - state.last_point,
)
.to_cols_array_2d(),
mode: GizmoMode::Translate,
value: state.current_delta.to_array(),
})
Expand Down

0 comments on commit 9fe5ac2

Please sign in to comment.