mirror of
https://github.com/bevyengine/bevy
synced 2024-12-30 06:53:13 +00:00
5aa998dc07
# Objective Allow interoperation between `Isometry3d` and the transform types from bevy_transform. At least in the short term, the primary goal is to allow the extraction of isometries from transform components by users. ## Solution - Add explicit `from_isometry`/`to_isometry` methods to `Transform`. - Add explicit `from_isometry`/`to_isometry` methods to `GlobalTransform`. The former is hidden (primarily for internal use), and the latter has the caveats originating in [`Affine3A::to_scale_rotation_translation`](https://docs.rs/glam/latest/glam/f32/struct.Affine3A.html#method.to_scale_rotation_translation). - Implement the `TransformPoint` trait for `Isometry3d`.
44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use bevy_math::{Affine3A, Isometry3d, Mat4, Vec3};
|
|
|
|
use crate::prelude::{GlobalTransform, Transform};
|
|
|
|
/// A trait for point transformation methods.
|
|
pub trait TransformPoint {
|
|
/// Transform a point.
|
|
fn transform_point(&self, point: impl Into<Vec3>) -> Vec3;
|
|
}
|
|
|
|
impl TransformPoint for Transform {
|
|
#[inline]
|
|
fn transform_point(&self, point: impl Into<Vec3>) -> Vec3 {
|
|
self.transform_point(point.into())
|
|
}
|
|
}
|
|
|
|
impl TransformPoint for GlobalTransform {
|
|
#[inline]
|
|
fn transform_point(&self, point: impl Into<Vec3>) -> Vec3 {
|
|
self.transform_point(point.into())
|
|
}
|
|
}
|
|
|
|
impl TransformPoint for Mat4 {
|
|
#[inline]
|
|
fn transform_point(&self, point: impl Into<Vec3>) -> Vec3 {
|
|
self.transform_point3(point.into())
|
|
}
|
|
}
|
|
|
|
impl TransformPoint for Affine3A {
|
|
#[inline]
|
|
fn transform_point(&self, point: impl Into<Vec3>) -> Vec3 {
|
|
self.transform_point3(point.into())
|
|
}
|
|
}
|
|
|
|
impl TransformPoint for Isometry3d {
|
|
#[inline]
|
|
fn transform_point(&self, point: impl Into<Vec3>) -> Vec3 {
|
|
self.transform_point(point.into()).into()
|
|
}
|
|
}
|