From 721922c4eae7b4ca7911f4ad7f7f877872748dc9 Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Sun, 3 Aug 2025 16:23:00 -0400 Subject: [PATCH] Fix inconsistent spawnpoint origins #30 --- Cargo.lock | 1 + Cargo.toml | 1 + rc_core/Cargo.toml | 1 + rc_core/src/persist/maps.rs | 40 +++++++++++++++++++++++++++++-------- rc_multiplayer/Cargo.toml | 2 +- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d1bb30c..ccf6503 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2671,6 +2671,7 @@ dependencies = [ "jsonwebtoken", "libfj", "log", + "num-quaternion", "oj_rc_database", "oj_rc_factory", "polariton 0.3.0", diff --git a/Cargo.toml b/Cargo.toml index f033f2f..cebf43b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,3 +45,4 @@ async-trait = "0.1" chrono = "0.4" git-version = "0.3" rand = { version = "0.9", features = [ "thread_rng" ] } +num-quaternion = "1.0" diff --git a/rc_core/Cargo.toml b/rc_core/Cargo.toml index 860d60e..b44ede7 100644 --- a/rc_core/Cargo.toml +++ b/rc_core/Cargo.toml @@ -18,6 +18,7 @@ polariton_server.workspace = true tokio = { version = "1.43", features = [ "net", "macros", "rt-multi-thread", "io-util", "time" ] } async-trait.workspace = true rand.workspace = true +num-quaternion.workspace = true # auth libfj.workspace = true diff --git a/rc_core/src/persist/maps.rs b/rc_core/src/persist/maps.rs index fe851fe..3b08de4 100644 --- a/rc_core/src/persist/maps.rs +++ b/rc_core/src/persist/maps.rs @@ -20,6 +20,25 @@ pub struct SpawnPoint { pub z: f32, } +impl SpawnPoint { + const fn offset(mut self, x: f32, y: f32, z: f32) -> Self { + self.x += x; + self.y += y; + self.z += z; + self + } + + fn rotated_from(mut self, x: f32, y: f32, z: f32, rot: num_quaternion::Quaternion) -> Self { + if let Some(unit_rot) = rot.normalize() { + let rotated = unit_rot.rotate_vector([self.x, self.y, self.z]); + self.x = rotated[0] + x; + self.y = rotated[1] + y; + self.z = rotated[2] + z; + } + self + } +} + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct CaptureBase { pub team: u8, @@ -43,7 +62,7 @@ pub(super) fn default_map() -> std::collections::HashMap std::collections::HashMap std::collections::HashMap std::collections::HashMap std::collections::HashMap std::collections::HashMap std::collections::HashMap std::collections::HashMap