f1_api/packet/
motion.rs

1//! Motion data on all cars in the session
2//!
3//! The F1 games provide data about the position and movement of each car in the session in the
4//! motion packet. The rate with which these packets are sent can be configured in the game. F1 2018
5//! and F1 2019 publish the same motion data.
6
7use derive_new::new;
8use getset::{CopyGetters, Getters};
9
10use crate::packet::header::Header;
11use crate::types::{CornerProperty, Property3D};
12
13/// Data about a car and its position and movement in space
14///
15/// The position and movement of each car in a session is described in the motion packet.
16#[derive(new, Debug, CopyGetters, Getters, PartialEq, Copy, Clone, PartialOrd, Default)]
17#[allow(clippy::too_many_arguments)]
18pub struct Motion {
19    /// Returns the position of the car in 3D space.
20    #[getset(get = "pub")]
21    position: Property3D<f32>,
22
23    /// Returns the velocity of the car on three axis.
24    #[getset(get = "pub")]
25    velocity: Property3D<f32>,
26
27    /// Returns the normalized forward motion of the car on three axis.
28    ///
29    /// Normalized values can be converted to float through division by 32767.0f.
30    #[getset(get = "pub")]
31    forward_direction: Property3D<i16>,
32
33    /// Returns the normalized lateral motion of the car on three axis.
34    ///
35    /// Normalized values can be converted to float through division by 32767.0f.
36    #[getset(get = "pub")]
37    right_direction: Property3D<i16>,
38
39    /// Returns the G force on the car on each of the three axis.
40    #[getset(get = "pub")]
41    g_force: Property3D<f32>,
42
43    /// Returns the yaw angle of the car in radians.
44    #[getset(get_copy = "pub")]
45    yaw: f32,
46
47    /// Returns the pitch angle of the car in radians.
48    #[getset(get_copy = "pub")]
49    pitch: f32,
50
51    /// Returns the roll angle of the car in radians.
52    #[getset(get_copy = "pub")]
53    roll: f32,
54}
55
56/// Packet containing data about the movement and position of all cars in the session
57///
58/// The F1 games publish motion data for all cars in the session. This data is restricted to
59/// publicly observable properties for most cars, e.g. the position and movement of a car. For the
60/// player's car, additional motion data is published, e.g. various physical forces on the car and
61/// its suspension.
62#[derive(new, Debug, CopyGetters, Getters, PartialEq, Clone, PartialOrd)]
63#[allow(clippy::too_many_arguments)]
64pub struct MotionPacket {
65    /// Returns the packet header prefixing the motion packet.
66    #[getset(get = "pub")]
67    header: Header,
68
69    /// Returns the publicly observable motion data for all 20 cars in the session.
70    #[getset(get = "pub")]
71    cars: Vec<Motion>,
72
73    /// Returns the position of the suspension at each corner of the car.
74    #[getset(get = "pub")]
75    suspension_position: CornerProperty<f32>,
76
77    /// Returns the velocity of the suspension at each corner of the car.
78    #[getset(get = "pub")]
79    suspension_velocity: CornerProperty<f32>,
80
81    /// Returns the acceleration of the suspension at each corner of the car.
82    #[getset(get = "pub")]
83    suspension_acceleration: CornerProperty<f32>,
84
85    /// Returns the wheel speed at each corner of the car.
86    #[getset(get = "pub")]
87    wheel_speed: CornerProperty<f32>,
88
89    /// Returns the wheel slip at each corner of the car.
90    #[getset(get = "pub")]
91    wheel_slip: CornerProperty<f32>,
92
93    /// Returns the velocity in local space on each axis.
94    #[getset(get = "pub")]
95    local_velocity: Property3D<f32>,
96
97    /// Returns the angular velocity on each axis.
98    #[getset(get = "pub")]
99    angular_velocity: Property3D<f32>,
100
101    /// Returns the angular acceleration on each axis.
102    #[getset(get = "pub")]
103    angular_acceleration: Property3D<f32>,
104
105    /// Returns the current angle of the front wheels in radians.
106    #[getset(get_copy = "pub")]
107    front_wheels_angle: f32,
108}