Skip to content

Commit

Permalink
Fix 3D rotation update in transform_to_position (#520)
Browse files Browse the repository at this point in the history
# Objective

Fixes #516.

Rotation is currently updated incorrectly in 3D by `transform_to_position`. It uses addition and subtraction instead of multiplication for quaternions. This causes clear desync between `Transform` rotation and `Rotation` when `SyncConfig::position_to_transform` is `false` and the `Transform` is changed:

https://github.com/user-attachments/assets/5b51480e-6f55-4317-9ed1-ec02f9c4d640

## Solution

Fix the rotation update. We can also remove the normalization, because individual quaternion multiplications should remain normalized, assuming the inputs are normalized (and there aren't too many successive rotations).

Now, the desync is fixed:

https://github.com/user-attachments/assets/8922832f-21b4-4ed9-947d-bd4b77786647
  • Loading branch information
Jondolf committed Sep 22, 2024
1 parent 7d79ca1 commit d79bb13
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,9 @@ pub fn transform_to_position(
#[cfg(feature = "3d")]
{
rotation.0 = (previous_transform.rotation
+ (transform.rotation - previous_transform.rotation)
+ (rotation.f32() - previous_transform.rotation))
.normalize()
.adjust_precision();
* (transform.rotation * previous_transform.rotation.inverse())
* (rotation.f32() * previous_transform.rotation.inverse()))
.adjust_precision();
}
}
}
Expand Down

0 comments on commit d79bb13

Please sign in to comment.