switched over to glam and simplified some imports

This commit is contained in:
Luuk van Oijen 2023-11-30 15:35:22 +01:00
parent dc61d4649c
commit 8e1d235dee
6 changed files with 33 additions and 158 deletions

134
Cargo.lock generated
View File

@ -65,15 +65,6 @@ version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]]
name = "argh"
version = "0.1.12"
@ -164,10 +155,10 @@ dependencies = [
"crossterm",
"flate2",
"futures",
"glam",
"lazy_static",
"log",
"mlua",
"nalgebra",
"num_enum",
"pretty_env_logger",
"ratatui",
@ -208,12 +199,6 @@ version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "bytemuck"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6"
[[package]]
name = "bytes"
version = "1.5.0"
@ -467,6 +452,12 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]]
name = "glam"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5418c17512bdf42730f9032c74e1ae39afc408745ebb2acf72fbc4691c17945"
[[package]]
name = "h2"
version = "0.3.21"
@ -764,16 +755,6 @@ dependencies = [
"which",
]
[[package]]
name = "matrixmultiply"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2"
dependencies = [
"autocfg",
"rawpointer",
]
[[package]]
name = "memchr"
version = "2.6.4"
@ -833,63 +814,6 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "nalgebra"
version = "0.31.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20bd243ab3dbb395b39ee730402d2e5405e448c75133ec49cc977762c4cba3d1"
dependencies = [
"approx",
"matrixmultiply",
"nalgebra-macros",
"num-complex",
"num-rational",
"num-traits",
"simba",
"typenum",
]
[[package]]
name = "nalgebra-macros"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01fcc0b8149b4632adc89ac3b7b31a12fb6099a0317a4eb2ebff574ef7de7218"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "num-complex"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214"
dependencies = [
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.17"
@ -1060,12 +984,6 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "rawpointer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "redox_syscall"
version = "0.4.1"
@ -1227,15 +1145,6 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "safe_arch"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f398075ce1e6a179b46f51bd88d0598b92b00d3551f1a2d4ac49e771b56ac354"
dependencies = [
"bytemuck",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
@ -1336,19 +1245,6 @@ dependencies = [
"libc",
]
[[package]]
name = "simba"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f3fd720c48c53cace224ae62bef1bbff363a70c68c4802a78b5cc6159618176"
dependencies = [
"approx",
"num-complex",
"num-traits",
"paste",
"wide",
]
[[package]]
name = "slab"
version = "0.4.9"
@ -1588,12 +1484,6 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-bidi"
version = "0.3.13"
@ -1765,16 +1655,6 @@ dependencies = [
"rustix",
]
[[package]]
name = "wide"
version = "0.7.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c68938b57b33da363195412cfc5fc37c9ed49aa9cfe2156fde64b8d2c9498242"
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -14,7 +14,7 @@ argh = "0.1.12"
lazy_static = "1"
anyhow = "1.0.66"
nalgebra = "0.31"
glam = "0.24.2"
num_enum = "0.5.7"
async-trait = "0.1.58"

View File

@ -1,15 +1,15 @@
use nalgebra::*;
use glam::*;
use std::time::{Instant, Duration};
use std::time::Instant;
#[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 pos: DVec3,
pub rot: DQuat,
pub vel: DVec3,
pub rvel: DVec3,
pub tim: f64,
pub ping: f64,
pub last_pos_update: Option<Instant>,
@ -24,12 +24,12 @@ impl Car {
}
}
pub fn pos(&self) -> Vector3<f64> {
pub fn position(&self) -> DVec3 {
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> {
pub fn rotation(&self) -> DQuat {
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()
self.rot + DQuat::from_euler(glam::EulerRot::YXZ, self.rvel.x * t, self.rvel.y * t, self.rvel.z * t)
}
}

View File

@ -2,9 +2,7 @@ use std::collections::HashMap;
use std::net::SocketAddr;
use std::ops::DerefMut;
use std::path::Path;
use std::sync::atomic::{AtomicU8, Ordering};
use std::sync::Arc;
use std::time::Instant;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{
@ -15,10 +13,7 @@ use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::Mutex;
use tokio::task::JoinHandle;
use nalgebra::*;
use serde::Deserialize;
use serde_aux::prelude::*;
use crate::fs_util;
use super::backend::*;

View File

@ -1,16 +1,14 @@
use std::net::SocketAddr;
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
use std::sync::Arc;
use std::time::Instant;
use std::collections::HashMap;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, UdpSocket};
use tokio::task::{JoinHandle, JoinSet};
use tokio::sync::{Mutex, mpsc, oneshot};
use tokio::sync::{mpsc, oneshot};
use num_enum::IntoPrimitive;
use nalgebra::*;
use glam::*;
mod backend;
mod car;
@ -27,7 +25,6 @@ pub use plugins::*;
pub use http::*;
pub use crate::config::Config;
use crate::config::GeneralSettings;
fn load_plugins(server_resource_folder: String) -> Vec<Plugin> {
let mut plugins = Vec::new();
@ -686,11 +683,11 @@ impl Server {
ServerBoundPluginEvent::RequestPositionRaw((pid, vid, responder)) => {
if let Some(client) = self.clients.iter().find(|client| client.id == pid) {
if let Some((_id, vehicle)) = client.cars.iter().find(|(id, _car)| *id == vid) {
// let pos_rot = PositionRaw {
// pos: vehicle.pos().
// };
todo!()
// let _ = responder.send(PluginBoundPluginEvent::PositionRaw(pos_rot));
let pos_rot = PositionRaw {
pos: vehicle.position().as_vec3().to_array(),
rot: vehicle.rotation().as_f32().to_array(),
};
let _ = responder.send(PluginBoundPluginEvent::PositionRaw(pos_rot));
} else {
let _ = responder.send(PluginBoundPluginEvent::None);
}
@ -972,11 +969,11 @@ impl Server {
.get_car_mut(car_id)
.ok_or(ServerError::CarDoesntExist)?;
car.pos = pos_data.pos.into();
car.rot = Quaternion::new(
pos_data.rot[3],
car.rot = DQuat::from_xyzw(
pos_data.rot[0],
pos_data.rot[1],
pos_data.rot[2],
pos_data.rot[3],
);
car.vel = pos_data.vel.into();
car.rvel = pos_data.rvel.into();

View File

@ -174,10 +174,13 @@ impl UserData for Context {
let message = rx.blocking_recv();
if let Ok(message) = message {
if let PluginBoundPluginEvent::PositionRaw(pos_raw) = message {
let pos_table = lua.create_table()?;
pos_table.set("x", pos_raw.pos[0])?;
pos_table.set("y", pos_raw.pos[1])?;
pos_table.set("z", pos_raw.pos[2])?;
let table = lua.create_table()?;
// for (vid, veh_json) in vehicles {
// table.set(vid, veh_json)?;
// }
table.set("pos", pos_table)?;
Ok(table)
} else {
unreachable!() // This really should never be reachable