nurtex_protocol/types/
rotation.rs1use std::io::{self, Cursor, Write};
2
3use nurtex_codec::Buffer;
4
5#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
7pub struct Rotation {
8 pub yaw: f32,
9 pub pitch: f32,
10}
11
12impl Rotation {
13 pub fn new(yaw: f32, pitch: f32) -> Self {
15 Self { yaw, pitch }
16 }
17
18 pub fn zero() -> Self {
20 Self { yaw: 0.0, pitch: 0.0 }
21 }
22
23 pub fn delta(&self, other: Rotation) -> Self {
25 let dyaw = self.yaw - other.yaw;
26 let dpitch = self.pitch - other.pitch;
27
28 Self { yaw: dyaw, pitch: dpitch }
29 }
30}
31
32impl Buffer for Rotation {
33 fn read_buf(buffer: &mut Cursor<&[u8]>) -> Option<Self> {
34 Some(Self {
35 yaw: f32::read_buf(buffer)?,
36 pitch: f32::read_buf(buffer)?,
37 })
38 }
39
40 fn write_buf(&self, buffer: &mut impl Write) -> io::Result<()> {
41 self.yaw.write_buf(buffer)?;
42 self.pitch.write_buf(buffer)?;
43 Ok(())
44 }
45}