dis_rust/common/euler_angles_record.rs
1// dis-rust - A rust implementation of the DIS simulation protocol.
2// Copyright (C) 2022 Thomas Mann
3//
4// This software is dual-licensed. It is available under the conditions of
5// the GNU Affero General Public License (see the LICENSE file included)
6// or under a commercial license (email contact@coffeebreakdevs.com for
7// details).
8
9use bytes::{BytesMut, BufMut, Buf};
10
11#[derive(Copy, Clone, Debug, Default)]
12/// Euler Angles Record as defined in IEEE 1278.1 standard. Used to communicate the orientation of an entity during the simulation.
13/// Uses radians as units.
14 pub struct EulerAnglesRecord {
15 pub psi_field: f32,
16 pub theta_field: f32,
17 pub phi_field: f32
18 }
19
20 impl EulerAnglesRecord {
21 /// Provides a function to create a new EulerAnglesRecord.
22 ///
23 /// # Examples
24 ///
25 /// Creating a blank EulerAnglesRecord:
26 ///
27 /// ```
28 /// let euler_angles_record = EulerAnglesRecord::new{
29 /// x: 0.0,
30 /// y: 0.0,
31 /// z: 0.0
32 /// };
33 /// ```
34 ///
35 pub fn new(psi: f32, theta: f32, phi: f32) -> Self {
36 EulerAnglesRecord {
37 psi_field: psi,
38 theta_field: theta,
39 phi_field: phi
40 }
41 }
42
43 /// Fills a BytesMut struct with a EulerAnglesRecord serialised into binary. This buffer is then ready to be sent via
44 /// UDP to the simluation network.
45 pub fn serialize(&self, buf: &mut BytesMut) {
46 buf.put_f32(self.psi_field);
47 buf.put_f32(self.theta_field);
48 buf.put_f32(self.phi_field);
49 }
50
51 pub fn decode(buf: &mut BytesMut) -> EulerAnglesRecord {
52 EulerAnglesRecord {
53 psi_field: buf.get_f32(),
54 theta_field: buf.get_f32(),
55 phi_field: buf.get_f32()
56 }
57 }
58 }