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: Rotation,
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: Rotation::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().adjust_precision(),
55 #[cfg(feature = "3d")]
56 translation: value.translation.adjust_precision(),
57 rotation: Rotation::from(value.rotation.adjust_precision()),
58 #[cfg(feature = "2d")]
59 scale: value.scale.truncate().adjust_precision(),
60 #[cfg(feature = "3d")]
61 scale: value.scale.adjust_precision(),
62 }
63 }
64}