mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-14 19:56:06 +00:00
initial commit
This commit is contained in:
35
src/server/car.rs
Normal file
35
src/server/car.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use nalgebra::*;
|
||||
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Car {
|
||||
pub car_json: String,
|
||||
|
||||
pub pos: Vector3<f64>,
|
||||
pub rot: Quaternion<f64>,
|
||||
pub vel: Vector3<f64>,
|
||||
pub rvel: Vector3<f64>,
|
||||
pub tim: f64,
|
||||
pub ping: f64,
|
||||
pub last_pos_update: Option<Instant>,
|
||||
}
|
||||
|
||||
impl Car {
|
||||
pub fn new(car_json: String) -> Self {
|
||||
Self {
|
||||
car_json: car_json,
|
||||
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pos(&self) -> Vector3<f64> {
|
||||
self.pos + self.vel * self.last_pos_update.map(|t| t.elapsed().as_secs_f64()).unwrap_or(0.0)
|
||||
}
|
||||
|
||||
pub fn rotation(&self) -> Quaternion<f64> {
|
||||
let t = self.last_pos_update.map(|t| t.elapsed().as_secs_f64()).unwrap_or(0.0);
|
||||
self.rot + UnitQuaternion::from_euler_angles(self.rvel.x * t, self.rvel.y * t, self.rvel.z * t).quaternion()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user