dis_rust/common/angular_velocity_vector_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/// Angular Velocity Record as defined in IEEE 1278.1 standard. Used to communicate the angular velocity of an entity in 3D during the simulation.
13 pub struct AngularVelocityRecord {
14 pub rate_about_x_axis_field: f32,
15 pub rate_about_y_axis_field: f32,
16 pub rate_about_z_axis_field: f32
17 }
18
19 impl AngularVelocityRecord {
20 /// Provides a function to create a new AngularVelocityRecord.
21 ///
22 /// # Examples
23 ///
24 /// Creating a blank AngularVelocityRecord:
25 ///
26 /// ```
27 /// let angular_velocity_record = AngularVelocityRecord::new{
28 /// x: 0.0,
29 /// y: 0.0,
30 /// z: 0.0
31 /// };
32 /// ```
33 ///
34 pub fn new(x: f32, y: f32, z: f32) -> Self {
35 AngularVelocityRecord {
36 rate_about_x_axis_field: x,
37 rate_about_y_axis_field: y,
38 rate_about_z_axis_field: z
39 }
40 }
41
42 /// Fills a BytesMut struct with a AngularVelocityRecord serialised into binary. This buffer is then ready to be sent via
43 /// UDP to the simluation network.
44 pub fn serialize(&self, buf: &mut BytesMut) {
45 buf.put_f32(self.rate_about_x_axis_field);
46 buf.put_f32(self.rate_about_y_axis_field);
47 buf.put_f32(self.rate_about_z_axis_field);
48 }
49
50 pub fn decode(buf: &mut BytesMut) -> AngularVelocityRecord {
51 AngularVelocityRecord {
52 rate_about_x_axis_field: buf.get_f32(),
53 rate_about_y_axis_field: buf.get_f32(),
54 rate_about_z_axis_field: buf.get_f32()
55 }
56 }
57 }