open_dis_rust/common/angular_velocity_vector.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.7
11/// For all fields, assume right-hand rule for directionality
12pub struct AngularVelocity {
13 /// The angular velocity in radians/second about the entity's X-axis
14 pub rate_about_x_axis: f32,
15 /// The angular velocity in radians/second about the entity's Y-axis
16 pub rate_about_y_axis: f32,
17 /// The angular velocity in radians/second about the entity's Z-axis
18 pub rate_about_z_axis: f32,
19}
20
21impl AngularVelocity {
22 /// Create a new `AngularVelocity` struct with existing values
23 #[must_use]
24 pub fn new(x: f32, y: f32, z: f32) -> Self {
25 AngularVelocity {
26 rate_about_x_axis: x,
27 rate_about_y_axis: y,
28 rate_about_z_axis: z,
29 }
30 }
31
32 /// Serialize an instance of an `AngularVelocity` into a mutable byte stream
33 pub fn serialize(&self, buf: &mut BytesMut) {
34 buf.put_f32(self.rate_about_x_axis);
35 buf.put_f32(self.rate_about_y_axis);
36 buf.put_f32(self.rate_about_z_axis);
37 }
38
39 /// Decode an `AngularVelocity` from a mutable byte stream
40 pub fn decode(buf: &mut BytesMut) -> AngularVelocity {
41 AngularVelocity {
42 rate_about_x_axis: buf.get_f32(),
43 rate_about_y_axis: buf.get_f32(),
44 rate_about_z_axis: buf.get_f32(),
45 }
46 }
47}