open_dis_rust/common/
entity_coordinate_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.96
11pub struct EntityCoordinateVector {
12    /// Location along the X-axis relative to the entity's origin
13    pub x_coordinate: f32,
14    /// Location along the Y-axis relative to the entity's origin
15    pub y_coordinate: f32,
16    /// Location along the Z-axis relative to the entity's origin
17    pub z_coordinate: f32,
18}
19
20impl EntityCoordinateVector {
21    #[must_use]
22    pub fn new(x: f32, y: f32, z: f32) -> Self {
23        EntityCoordinateVector {
24            x_coordinate: x,
25            y_coordinate: y,
26            z_coordinate: z,
27        }
28    }
29
30    pub fn serialize(&self, buf: &mut BytesMut) {
31        buf.put_f32(self.x_coordinate);
32        buf.put_f32(self.y_coordinate);
33        buf.put_f32(self.z_coordinate);
34    }
35
36    pub fn decode(buf: &mut BytesMut) -> EntityCoordinateVector {
37        EntityCoordinateVector {
38            x_coordinate: buf.get_f32(),
39            y_coordinate: buf.get_f32(),
40            z_coordinate: buf.get_f32(),
41        }
42    }
43}