Closed
Description
Bevy version
0.16
What you did
let bullet_rotation = transform.rotation.to_euler(EulerRot::XYZ).2;
let bullet_aabb = Aabb2d::new(Vec2::ZERO, BULLET_SIZE / 2.0).rotated_by(bullet_rotation);
What went wrong
I was expected Aabb2d
to rotate by any angle between -PI
and PI
, but instead get assertion failed: half_size.x >= 0.0 && half_size.y >= 0.0
at bevy_math-0.16.0/src/bounding/bounded2d/mod.rs:61:9
.
Additional information
I investigated this and found that rotate_by
implementation is probably incorrect:
fn rotate_by(&mut self, rotation: impl Into<Self::Rotation>) {
let rotation: Rot2 = rotation.into();
let abs_rot_mat = Mat2::from_cols(
Vec2::new(rotation.cos, rotation.sin),
Vec2::new(rotation.sin, rotation.cos),
);
let half_size = abs_rot_mat * self.half_size();
*self = Self::new(rotation * self.center(), half_size);
}
As name of abs_rot_mat
suggests it should have absolute values, so my current fixed version looks like this:
fn rotate_by(&mut self, rotation: impl Into<Self::Rotation>) {
let rotation: Rot2 = rotation.into();
let rot_mat = Mat2::from_cols(
Vec2::new(rotation.cos, rotation.sin),
Vec2::new(rotation.sin, rotation.cos),
);
let half_size = rot_mat.abs() * self.half_size();
*self = Self::new(rotation * self.center(), half_size);
}