use bevy_math::{EulerRot, Quat as BevyQuat, Vec2 as BevyVec2, Vec3 as BevyVec3};
use bevy_transform::components::Transform as BevyTransform;
#[inline]
pub fn to_boxdd_vec2(value: BevyVec2) -> boxdd::Vec2 {
boxdd::Vec2::new(value.x, value.y)
}
#[inline]
pub fn to_boxdd_translation(value: BevyVec3) -> boxdd::Vec2 {
boxdd::Vec2::new(value.x, value.y)
}
#[inline]
pub fn to_boxdd_angle(value: BevyQuat) -> f32 {
value.to_euler(EulerRot::XYZ).2
}
#[inline]
pub fn to_boxdd_transform(value: BevyTransform) -> boxdd::Transform {
boxdd::Transform::from_pos_angle(
to_boxdd_translation(value.translation),
to_boxdd_angle(value.rotation),
)
}
#[inline]
pub fn to_bevy_vec2(value: boxdd::Vec2) -> BevyVec2 {
BevyVec2::new(value.x, value.y)
}
#[inline]
pub fn to_bevy_translation(value: boxdd::Vec2, z: f32) -> BevyVec3 {
BevyVec3::new(value.x, value.y, z)
}
#[inline]
pub fn to_bevy_rotation(value: boxdd::Rot) -> BevyQuat {
BevyQuat::from_rotation_z(value.angle())
}
#[inline]
pub fn to_bevy_transform(value: boxdd::Transform) -> BevyTransform {
BevyTransform::from_translation(to_bevy_translation(value.position(), 0.0))
.with_rotation(to_bevy_rotation(value.rotation()))
}
#[inline]
pub fn apply_boxdd_transform(target: &mut BevyTransform, value: boxdd::Transform) {
let z = target.translation.z;
target.translation = to_bevy_translation(value.position(), z);
target.rotation = to_bevy_rotation(value.rotation());
}
pub trait BevyVec2BoxddExt {
fn to_boxdd_vec2(self) -> boxdd::Vec2;
}
impl BevyVec2BoxddExt for BevyVec2 {
#[inline]
fn to_boxdd_vec2(self) -> boxdd::Vec2 {
to_boxdd_vec2(self)
}
}
pub trait BevyQuatBoxddExt {
fn to_boxdd_angle(self) -> f32;
}
impl BevyQuatBoxddExt for BevyQuat {
#[inline]
fn to_boxdd_angle(self) -> f32 {
to_boxdd_angle(self)
}
}
pub trait BevyTransformBoxddExt {
fn to_boxdd_transform(self) -> boxdd::Transform;
}
impl BevyTransformBoxddExt for BevyTransform {
#[inline]
fn to_boxdd_transform(self) -> boxdd::Transform {
to_boxdd_transform(self)
}
}
pub trait BoxddVec2BevyExt {
fn to_bevy_vec2(self) -> BevyVec2;
}
impl BoxddVec2BevyExt for boxdd::Vec2 {
#[inline]
fn to_bevy_vec2(self) -> BevyVec2 {
to_bevy_vec2(self)
}
}
pub trait BoxddQuatBevyExt {
fn to_bevy_quat(self) -> BevyQuat;
}
impl BoxddQuatBevyExt for boxdd::Rot {
#[inline]
fn to_bevy_quat(self) -> BevyQuat {
to_bevy_rotation(self)
}
}
pub trait BoxddTransformBevyExt {
fn to_bevy_transform(self) -> BevyTransform;
fn apply_to_bevy_transform(self, target: &mut BevyTransform);
}
impl BoxddTransformBevyExt for boxdd::Transform {
#[inline]
fn to_bevy_transform(self) -> BevyTransform {
to_bevy_transform(self)
}
#[inline]
fn apply_to_bevy_transform(self, target: &mut BevyTransform) {
apply_boxdd_transform(target, self);
}
}