Merge branch 'sam/remove-angle-between' into 'master'

Removed angle between with dot product in handle_orientation.

See merge request veloren/veloren!2933
This commit is contained in:
Samuel Keiffer 2021-10-16 04:42:29 +00:00
commit 2c9736268d
2 changed files with 6 additions and 2 deletions

View File

@ -208,6 +208,8 @@ impl Ori {
if angle < PI { angle } else { TAU - angle }
}
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))
}

View File

@ -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)).sqrt();
data.body.base_ori_rate() * efficiency * angle_factor
};
update.ori = update
.ori