Skip to content

Commit

Permalink
More minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
urholaukkarinen committed Feb 1, 2024
1 parent 851a764 commit 38e5fa0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
33 changes: 13 additions & 20 deletions src/subgizmo/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn pick_plane<T: SubGizmoKind>(
ray: Ray,
direction: GizmoDirection,
) -> PickResult {
let origin = plane_global_origin(subgizmo, direction);
let origin = plane_global_origin(&subgizmo.config, direction);

let normal = gizmo_normal(&subgizmo.config, direction);

Expand All @@ -87,7 +87,7 @@ pub(crate) fn pick_plane<T: SubGizmoKind>(
- ((1.0 - dot) - *PLANE_FADE.start()) / (*PLANE_FADE.end() - *PLANE_FADE.start()))
.min(1.0);

let picked = visibility > 0.0 && dist_from_origin <= plane_size(subgizmo);
let picked = visibility > 0.0 && dist_from_origin <= plane_size(&subgizmo.config);

PickResult {
subgizmo_point: ray_point,
Expand Down Expand Up @@ -204,10 +204,10 @@ pub(crate) fn draw_plane<T: SubGizmoKind>(
subgizmo.config.viewport,
);

let scale = plane_size(subgizmo) * 0.5;
let scale = plane_size(&subgizmo.config) * 0.5;
let a = plane_bitangent(direction) * scale;
let b = plane_tangent(direction) * scale;
let origin = plane_local_origin(subgizmo, direction);
let origin = plane_local_origin(&subgizmo.config, direction);

painter.polygon(
&[
Expand Down Expand Up @@ -275,32 +275,25 @@ pub(crate) fn plane_tangent(direction: GizmoDirection) -> DVec3 {
}
}

pub(crate) fn plane_size<T: SubGizmoKind>(subgizmo: &SubGizmoConfig<T>) -> f64 {
(subgizmo.config.scale_factor
* (subgizmo.config.visuals.gizmo_size * 0.1 + subgizmo.config.visuals.stroke_width * 2.0))
pub(crate) fn plane_size(config: &GizmoConfig) -> f64 {
(config.scale_factor * (config.visuals.gizmo_size * 0.1 + config.visuals.stroke_width * 2.0))
as f64
}

pub(crate) fn plane_local_origin<T: SubGizmoKind>(
subgizmo: &SubGizmoConfig<T>,
direction: GizmoDirection,
) -> DVec3 {
let offset = subgizmo.config.scale_factor * subgizmo.config.visuals.gizmo_size * 0.5;
pub(crate) fn plane_local_origin(config: &GizmoConfig, direction: GizmoDirection) -> DVec3 {
let offset = config.scale_factor * config.visuals.gizmo_size * 0.5;

let a = plane_bitangent(direction);
let b = plane_tangent(direction);
(a + b) * offset as f64
}

pub(crate) fn plane_global_origin<T: SubGizmoKind>(
subgizmo: &SubGizmoConfig<T>,
direction: GizmoDirection,
) -> DVec3 {
let mut origin = plane_local_origin(subgizmo, direction);
if subgizmo.config.local_space() {
origin = subgizmo.config.rotation * origin;
pub(crate) fn plane_global_origin(config: &GizmoConfig, direction: GizmoDirection) -> DVec3 {
let mut origin = plane_local_origin(config, direction);
if config.local_space() {
origin = config.rotation * origin;
}
origin + subgizmo.config.translation
origin + config.translation
}

/// Radius to use for inner circle subgizmos
Expand Down
2 changes: 1 addition & 1 deletion src/subgizmo/scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl SubGizmoKind for Scale {
impl SubGizmo for ScaleSubGizmo {
fn pick(&mut self, ui: &Ui, ray: Ray) -> Option<f64> {
let pick_result = match (self.transform_kind, self.direction) {
(TransformKind::Axis, _) => pick_arrow(self, ray, self.direction),
(TransformKind::Plane, GizmoDirection::View) => {
let mut result = pick_circle(self, ray, inner_circle_radius(&self.config), true);
if !result.picked {
Expand All @@ -45,6 +44,7 @@ impl SubGizmo for ScaleSubGizmo {
result
}
(TransformKind::Plane, _) => pick_plane(self, ray, self.direction),
(TransformKind::Axis, _) => pick_arrow(self, ray, self.direction),
};

let start_delta = distance_from_origin_2d(self, ui)?;
Expand Down
2 changes: 1 addition & 1 deletion src/subgizmo/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl SubGizmo for TranslationSubGizmo {
} else {
point_on_plane(
gizmo_normal(&self.config, self.direction),
plane_global_origin(self, self.direction),
plane_global_origin(&self.config, self.direction),
ray,
)?
};
Expand Down

0 comments on commit 38e5fa0

Please sign in to comment.