dis_rs/common/collision_elastic/
parser.rs1use crate::common::collision_elastic::model::CollisionElastic;
2use crate::common::model::PduBody;
3use crate::common::parser::{entity_id, event_id, vec3_f32};
4use nom::number::complete::{be_f32, be_u16};
5use nom::IResult;
6
7#[allow(clippy::similar_names)]
8pub(crate) fn collision_elastic_body(input: &[u8]) -> IResult<&[u8], PduBody> {
9 let (input, issuing_entity_id) = entity_id(input)?;
10 let (input, colliding_entity_id) = entity_id(input)?;
11 let (input, event_id) = event_id(input)?;
12 let (input, _padding) = be_u16(input)?;
13 let (input, velocity) = vec3_f32(input)?;
14 let (input, mass) = be_f32(input)?;
15 let (input, location) = vec3_f32(input)?;
16 let (input, intermediate_result_xx) = be_f32(input)?;
17 let (input, intermediate_result_xy) = be_f32(input)?;
18 let (input, intermediate_result_xz) = be_f32(input)?;
19 let (input, intermediate_result_yy) = be_f32(input)?;
20 let (input, intermediate_result_yz) = be_f32(input)?;
21 let (input, intermediate_result_zz) = be_f32(input)?;
22 let (input, unit_surface_normal) = vec3_f32(input)?;
23 let (input, coefficient_of_restitution) = be_f32(input)?;
24
25 let body = CollisionElastic::builder()
26 .with_issuing_entity_id(issuing_entity_id)
27 .with_colliding_entity_id(colliding_entity_id)
28 .with_event_id(event_id)
29 .with_velocity(velocity)
30 .with_mass(mass)
31 .with_location(location)
32 .with_intermediate_result_xx(intermediate_result_xx)
33 .with_intermediate_result_xy(intermediate_result_xy)
34 .with_intermediate_result_xz(intermediate_result_xz)
35 .with_intermediate_result_yy(intermediate_result_yy)
36 .with_intermediate_result_yz(intermediate_result_yz)
37 .with_intermediate_result_zz(intermediate_result_zz)
38 .with_unit_surface_normal(unit_surface_normal)
39 .with_coefficient_of_restitution(coefficient_of_restitution)
40 .build();
41
42 Ok((input, body.into_pdu_body()))
43}