f1_game_packet_parser/packets/motion.rs
1use binrw::BinRead;
2use serde::{Deserialize, Serialize};
3
4#[derive(BinRead, PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize)]
5#[br(little, import(_packet_format: u16))]
6pub struct CarMotionData {
7 /// World space X position in metres.
8 pub world_position_x: f32,
9 /// World space Y position in metres.
10 pub world_position_y: f32,
11 /// World space Z position in metres.
12 pub world_position_z: f32,
13 /// Velocity in world space X position in metres per second.
14 pub world_velocity_x: f32,
15 /// Velocity in world space Y position in metres per second.
16 pub world_velocity_y: f32,
17 /// Velocity in world space Z position in metres per second.
18 pub world_velocity_z: f32,
19 /// World space forward X direction (normalised).
20 pub world_forward_dir_x: i16,
21 /// World space forward Y direction (normalised).
22 pub world_forward_dir_y: i16,
23 /// World space forward Z direction (normalised).
24 pub world_forward_dir_z: i16,
25 /// World space right X direction (normalised).
26 pub world_right_dir_x: i16,
27 /// World space right Y direction (normalised).
28 pub world_right_dir_y: i16,
29 /// World space right Z direction (normalised).
30 pub world_right_dir_z: i16,
31 /// Lateral G-Force component.
32 pub g_force_lateral: f32,
33 /// Longitudinal G-Force component.
34 pub g_force_longitudinal: f32,
35 /// Vertical G-Force component.
36 pub g_force_vertical: f32,
37 /// Yaw angle in radians.
38 pub yaw: f32,
39 /// Pitch angle in radians.
40 pub pitch: f32,
41 /// Roll angle in radians.
42 pub roll: f32,
43}
44
45impl CarMotionData {
46 /// Returns [`world_forward_dir_x`](field@CarMotionData::world_forward_dir_x)
47 /// divided by `32767.0f32`.
48 pub fn world_forward_dir_x_as_f32(&self) -> f32 {
49 f32::from(self.world_forward_dir_x) / 32767.0
50 }
51
52 /// Returns [`world_forward_dir_y`](field@CarMotionData::world_forward_dir_y)
53 /// divided by `32767.0f32`.
54 pub fn world_forward_dir_y_as_f32(&self) -> f32 {
55 f32::from(self.world_forward_dir_y) / 32767.0
56 }
57
58 /// Returns [`world_forward_dir_z`](field@CarMotionData::world_forward_dir_z)
59 /// divided by `32767.0f32`.
60 pub fn world_forward_dir_z_as_f32(&self) -> f32 {
61 f32::from(self.world_forward_dir_z) / 32767.0
62 }
63
64 /// Returns [`world_right_dir_x`](field@CarMotionData::world_right_dir_x)
65 /// divided by `32767.0f32`.
66 pub fn world_right_dir_x_as_f32(&self) -> f32 {
67 f32::from(self.world_right_dir_x) / 32767.0
68 }
69
70 /// Returns [`world_right_dir_y`](field@CarMotionData::world_right_dir_y)
71 /// divided by `32767.0f32`.
72 pub fn world_right_dir_y_as_f32(&self) -> f32 {
73 f32::from(self.world_right_dir_y) / 32767.0
74 }
75
76 /// Returns [`world_right_dir_z`](field@CarMotionData::world_right_dir_z)
77 /// divided by `32767.0f32`.
78 pub fn world_right_dir_z_as_f32(&self) -> f32 {
79 f32::from(self.world_right_dir_z) / 32767.0
80 }
81}