avian3d/collision/collider/collider_transform/
mod.rs1mod plugin;
4
5pub use plugin::ColliderTransformPlugin;
6
7use crate::prelude::*;
8use bevy::prelude::*;
9
10#[derive(Reflect, Clone, Copy, Component, Debug, PartialEq)]
17#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
18#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
19#[reflect(Debug, Component, PartialEq)]
20pub struct ColliderTransform {
21 pub translation: Vector,
23 pub rotation: Rot,
25 pub scale: Vector,
27}
28
29impl ColliderTransform {
30 pub fn transform_point(&self, mut point: Vector) -> Vector {
33 point *= self.scale;
34 point = self.rotation * point;
35 point += self.translation;
36 point
37 }
38}
39
40impl Default for ColliderTransform {
41 fn default() -> Self {
42 Self {
43 translation: Vector::ZERO,
44 rotation: Rot::default(),
45 scale: Vector::ONE,
46 }
47 }
48}
49
50impl From<Transform> for ColliderTransform {
51 fn from(value: Transform) -> Self {
52 Self {
53 #[cfg(feature = "2d")]
54 translation: value.translation.truncate(),
55 #[cfg(feature = "3d")]
56 translation: value.translation,
57 #[cfg(feature = "2d")]
58 rotation: Rot::radians(value.rotation.to_euler(EulerRot::XYZ).2),
59 #[cfg(feature = "3d")]
60 rotation: value.rotation,
61 #[cfg(feature = "2d")]
62 scale: value.scale.truncate(),
63 #[cfg(feature = "3d")]
64 scale: value.scale,
65 }
66 }
67}