From 7b2ade34c4e5e320757e70a9dab01b6ac4f31b4a Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 15 Oct 2021 17:23:35 -0400 Subject: [PATCH 1/2] Removed angle between with dot product in handle_orientation. --- common/src/comp/ori.rs | 2 ++ common/src/states/utils.rs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/common/src/comp/ori.rs b/common/src/comp/ori.rs index 025b759b22..4b4e90963e 100644 --- a/common/src/comp/ori.rs +++ b/common/src/comp/ori.rs @@ -208,6 +208,8 @@ impl Ori { if angle < PI { angle } else { TAU - angle } } + pub fn dot(self, other: Self) -> f32 { self.0.dot(other.0) } + pub fn pitched_up(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_x(angle_radians)) } diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 6bfe1a8885..65a51b9a91 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -404,8 +404,10 @@ pub fn handle_orientation( .map_or_else(|| data.ori.to_horizontal(), |dir| dir.into()) }; let rate = { - let angle = update.ori.angle_between(target_ori); - data.body.base_ori_rate() * efficiency * std::f32::consts::PI / angle + // Angle factor used to keep turning rate approximately constant by + // counteracting slerp turning more with a larger angle + let angle_factor = 2.0 / (1.0 - update.ori.dot(target_ori)); + data.body.base_ori_rate() * efficiency * angle_factor }; update.ori = update .ori From c5c70f6945d555755ab333da71dd45390e4b2318 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 15 Oct 2021 22:41:53 -0400 Subject: [PATCH 2/2] Correctly took dot product, switched to square root of dot product --- common/src/comp/ori.rs | 2 +- common/src/states/utils.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/comp/ori.rs b/common/src/comp/ori.rs index 4b4e90963e..7f3bb40198 100644 --- a/common/src/comp/ori.rs +++ b/common/src/comp/ori.rs @@ -208,7 +208,7 @@ impl Ori { if angle < PI { angle } else { TAU - angle } } - pub fn dot(self, other: Self) -> f32 { self.0.dot(other.0) } + pub fn dot(self, other: Self) -> f32 { self.look_vec().dot(other.look_vec()) } pub fn pitched_up(self, angle_radians: f32) -> Self { self.rotated(Quaternion::rotation_x(angle_radians)) diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 65a51b9a91..a296d51d63 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -406,7 +406,7 @@ pub fn handle_orientation( let rate = { // Angle factor used to keep turning rate approximately constant by // counteracting slerp turning more with a larger angle - let angle_factor = 2.0 / (1.0 - update.ori.dot(target_ori)); + let angle_factor = 2.0 / (1.0 - update.ori.dot(target_ori)).sqrt(); data.body.base_ori_rate() * efficiency * angle_factor }; update.ori = update