Created
July 30, 2022 07:03
-
-
Save Dygear/9a82bfc53e57b3b0a247645bf83eef69 to your computer and use it in GitHub Desktop.
Primatives taking a slice would be cool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* # Motion Packet | |
* The motion packet gives physics data for all the cars being driven. There is additional data for the car being driven with the goal of being able to drive a motion platform setup. | |
* N.B. For the normalised vectors below, to convert to float values divide by 32767.0f – 16-bit signed values are used to pack the data and on the assumption that direction values are always between -1.0f and 1.0f. | |
* Frequency: Rate as specified in menus | |
* Size: 1464 bytes | |
* Version: 1 | |
*/ | |
#[derive(Debug, Clone, Copy)] | |
pub struct CarMotion | |
{ | |
pub worldPositionX: f32, // World space X position | |
pub worldPositionY: f32, // World space Y position | |
pub worldPositionZ: f32, // World space Z position | |
pub worldVelocityX: f32, // Velocity in world space X | |
pub worldVelocityY: f32, // Velocity in world space Y | |
pub worldVelocityZ: f32, // Velocity in world space Z | |
pub worldForwardDirX: i16, // World space forward X direction (normalised) | |
pub worldForwardDirY: i16, // World space forward Y direction (normalised) | |
pub worldForwardDirZ: i16, // World space forward Z direction (normalised) | |
pub worldRightDirX: i16, // World space right X direction (normalised) | |
pub worldRightDirY: i16, // World space right Y direction (normalised) | |
pub worldRightDirZ: i16, // World space right Z direction (normalised) | |
pub gForceLateral: f32, // Lateral G-Force component | |
pub gForceLongitudinal: f32, // Longitudinal G-Force component | |
pub gForceVertical: f32, // Vertical G-Force component | |
pub yaw: f32, // Yaw angle in radians | |
pub pitch: f32, // Pitch angle in radians | |
pub roll: f32, // Roll angle in radians | |
} | |
impl CarMotion | |
{ | |
pub fn unpack(bytes: &[u8]) -> Self | |
{ | |
Self { | |
worldPositionX : f32::from_le_bytes([bytes[0..3]]), | |
worldPositionY : f32::from_le_bytes([bytes[4..7]]), | |
worldPositionZ : f32::from_le_bytes([bytes[8..11]]), | |
worldVelocityX : f32::from_le_bytes([bytes[12..15]]), | |
worldVelocityY : f32::from_le_bytes([bytes[16..19]]), | |
worldVelocityZ : f32::from_le_bytes([bytes[20..23]]), | |
worldForwardDirX : i16::from_le_bytes([bytes[24..25]]), | |
worldForwardDirY : i16::from_le_bytes([bytes[26..27]]), | |
worldForwardDirZ : i16::from_le_bytes([bytes[28..29]]), | |
worldRightDirX : i16::from_le_bytes([bytes[30..31]]), | |
worldRightDirY : i16::from_le_bytes([bytes[32..33]]), | |
worldRightDirZ : i16::from_le_bytes([bytes[34..35]]), | |
gForceLateral : f32::from_le_bytes([bytes[36..39]]), | |
gForceLongitudinal: f32::from_le_bytes([bytes[40..43]]), | |
gForceVertical : f32::from_le_bytes([bytes[44..47]]), | |
yaw : f32::from_le_bytes([bytes[48..51]]), | |
pitch : f32::from_le_bytes([bytes[52..55]]), | |
roll : f32::from_le_bytes([bytes[56..59]]), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ideally you wouldn't even need the wrapping [] in the function call.