open_dis_rust/common/
euler_angles.rs

1//     open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
2//                     Simulation (DIS) application protocol
3//     Copyright (C) 2023 Cameron Howell
4//
5//     Licensed under the BSD 2-Clause License
6
7use bytes::{Buf, BufMut, BytesMut};
8
9#[derive(Copy, Clone, Debug, Default)]
10/// Implemented according to IEEE 1278.1-2012 ยง6.2.32
11pub struct EulerAngles {
12    /// Angle of rotation about the Z-axis
13    pub psi: f32,
14    /// Angle of rotation about the Y-axis
15    pub theta: f32,
16    /// Angle of rotation about the X-axis
17    pub phi: f32,
18}
19
20impl EulerAngles {
21    #[must_use]
22    #[allow(clippy::similar_names)]
23    pub fn new(psi: f32, theta: f32, phi: f32) -> Self {
24        EulerAngles { psi, theta, phi }
25    }
26
27    pub fn serialize(&self, buf: &mut BytesMut) {
28        buf.put_f32(self.psi);
29        buf.put_f32(self.theta);
30        buf.put_f32(self.phi);
31    }
32
33    pub fn decode(buf: &mut BytesMut) -> EulerAngles {
34        EulerAngles {
35            psi: buf.get_f32(),
36            theta: buf.get_f32(),
37            phi: buf.get_f32(),
38        }
39    }
40}