Skip to content

Commit

Permalink
Change how origin is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Weasy666 committed Apr 10, 2023
1 parent fd150f4 commit 7593d8d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Update bevy to `0.10`

### Removed
- `apply_origin` code commented out, because `GlobalTransform.translation_mut()` was made private. This means, that changing the origin does currently not change anything on the positioning of the `Svg` it will always appear as `Origin::TopLeft`.
- because `GlobalTransform.translation_mut()` was made private we now replace the `GlobalTransform` of an `Svg` when its `Origin` changes.

## [0.9.0] - 2023-01-17
### Added
Expand Down
64 changes: 33 additions & 31 deletions src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,40 @@ pub(crate) fn apply_origin(
)>,
>,
) {
// for (
// _,
// svg_handle,
// origin,
// mut origin_state,
// transform,
// transform_changed,
// mut global_transform,
// ) in &mut query
// {
// if let Some(svg) = svgs.get(svg_handle) {
// if origin_state.previous != *origin {
// let scaled_size = svg.size * transform.scale.xy();
// let reverse_origin_translation =
// origin_state.previous.compute_translation(scaled_size);
// let origin_translation = origin.compute_translation(scaled_size);
for (
_,
svg_handle,
origin,
mut origin_state,
transform,
transform_changed,
mut global_transform,
) in &mut query
{
if let Some(svg) = svgs.get(svg_handle) {
if origin_state.previous != *origin {
let scaled_size = svg.size * transform.scale.xy();
let reverse_origin_translation =
origin_state.previous.compute_translation(scaled_size);
let origin_translation = origin.compute_translation(scaled_size);

// let gtrans = global_transform.translation_mut();
// gtrans.x += origin_translation.x - reverse_origin_translation.x;
// gtrans.y += origin_translation.y - reverse_origin_translation.y;
// gtrans.z += origin_translation.z - reverse_origin_translation.z;
let mut gtransf = global_transform.compute_transform();
gtransf.translation.x += origin_translation.x - reverse_origin_translation.x;
gtransf.translation.y += origin_translation.y - reverse_origin_translation.y;
gtransf.translation.z += origin_translation.z - reverse_origin_translation.z;
*global_transform = GlobalTransform::from(gtransf);

// origin_state.previous = origin.clone();
// } else if transform_changed {
// let scaled_size = svg.size * transform.scale.xy();
// let origin_translation = origin.compute_translation(scaled_size);
origin_state.previous = origin.clone();
} else if transform_changed {
let scaled_size = svg.size * transform.scale.xy();
let origin_translation = origin.compute_translation(scaled_size);

// let gtrans = global_transform.translation_mut();
// gtrans.x += origin_translation.x;
// gtrans.y += origin_translation.y;
// gtrans.z += origin_translation.z;
// }
// }
// }
let mut gtransf = global_transform.compute_transform();
gtransf.translation.x += origin_translation.x;
gtransf.translation.y += origin_translation.y;
gtransf.translation.z += origin_translation.z;
*global_transform = GlobalTransform::from(gtransf);
}
}
}
}

0 comments on commit 7593d8d

Please sign in to comment.