1use std::marker::PhantomData;
2
3use glam::{Quat, Vec3};
4
5use crate::{
6 driver::RigDriver, handedness::Handedness, rig::RigUpdateParams, transform::Transform,
7};
8
9#[derive(Debug)]
11pub struct Arm {
12 pub offset: mint::Vector3<f32>,
13}
14
15impl Arm {
16 pub fn new<V>(offset: V) -> Self
17 where
18 V: Into<mint::Vector3<f32>>,
19 {
20 let offset = offset.into();
21
22 Self { offset }
23 }
24}
25
26impl<H: Handedness> RigDriver<H> for Arm {
27 fn update(&mut self, params: RigUpdateParams<H>) -> Transform<H> {
28 let parent_position: Vec3 = params.parent.position.into();
29 let parent_rotation: Quat = params.parent.rotation.into();
30 let offset: Vec3 = self.offset.into();
31
32 let position = parent_position + parent_rotation * offset;
33
34 Transform {
35 rotation: params.parent.rotation,
36 position: position.into(),
37 phantom: PhantomData,
38 }
39 }
40}