use super::Transform3D;
use crate::datatypes::{
Rotation3D, Scale3D, Transform3D as Transform3DDatatype, TranslationAndMat3x3,
TranslationRotationScale3D, Vec3D,
};
impl Transform3D {
pub const IDENTITY: Self = Self(Transform3DDatatype::IDENTITY);
#[inline]
pub fn new<T: Into<Transform3DDatatype>>(t: T) -> Self {
Self(t.into())
}
#[inline]
pub fn from_translation(translation: impl Into<Vec3D>) -> Self {
Self::from(TranslationRotationScale3D::from_translation(translation))
}
#[inline]
pub fn from_translation_rotation(
translation: impl Into<Vec3D>,
rotation: impl Into<Rotation3D>,
) -> Self {
Self::from(TranslationRotationScale3D::from_translation_rotation(
translation,
rotation,
))
}
#[inline]
pub fn from_translation_mat3x3(
translation: impl Into<Vec3D>,
mat3x3: impl Into<crate::datatypes::Mat3x3>,
) -> Self {
Self::from(TranslationAndMat3x3::new(translation, mat3x3))
}
#[inline]
pub fn from_translation_rotation_scale(
translation: impl Into<Vec3D>,
rotation: impl Into<Rotation3D>,
scale: impl Into<Scale3D>,
) -> Self {
Self::from(TranslationRotationScale3D::from_translation_rotation_scale(
translation,
rotation,
scale,
))
}
#[inline]
pub fn from_rotation_scale(rotation: impl Into<Rotation3D>, scale: impl Into<Scale3D>) -> Self {
Self::from(TranslationRotationScale3D::from_rotation_scale(
rotation, scale,
))
}
#[inline]
#[allow(clippy::wrong_self_convention)]
pub fn from_parent(mut self) -> Self {
self.0 = self.0.from_parent();
self
}
}
#[cfg(feature = "glam")]
impl Transform3D {
#[inline]
pub fn into_parent_from_child_transform(self) -> glam::Affine3A {
let transform: glam::Affine3A = self.0.into();
if self.0.is_from_parent() {
transform.inverse()
} else {
transform
}
}
#[inline]
pub fn into_child_from_parent_transform(self) -> glam::Affine3A {
let transform: glam::Affine3A = self.0.into();
if self.0.is_from_parent() {
transform
} else {
transform.inverse()
}
}
}