mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
the fix (#772)
This commit is contained in:
@@ -29,14 +29,11 @@ use pumpkin_util::math::{
|
||||
wrap_degrees,
|
||||
};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
f32::consts::PI,
|
||||
sync::{
|
||||
Arc,
|
||||
atomic::{
|
||||
AtomicBool, AtomicI32,
|
||||
Ordering::{Relaxed, SeqCst},
|
||||
},
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{
|
||||
AtomicBool, AtomicI32,
|
||||
Ordering::{Relaxed, SeqCst},
|
||||
},
|
||||
};
|
||||
use tokio::sync::RwLock;
|
||||
@@ -375,33 +372,25 @@ impl Entity {
|
||||
}
|
||||
|
||||
pub fn get_facing(&self) -> Facing {
|
||||
let pitch = self.pitch.load() * (PI / 180.0);
|
||||
let yaw = -self.yaw.load() * (PI / 180.0);
|
||||
let pitch = self.pitch.load().to_radians();
|
||||
let yaw = -self.yaw.load().to_radians();
|
||||
|
||||
let sin_pitch = pitch.sin();
|
||||
let cos_pitch = pitch.cos();
|
||||
let sin_yaw = yaw.sin();
|
||||
let cos_yaw = yaw.cos();
|
||||
let (sin_p, cos_p) = pitch.sin_cos();
|
||||
let (sin_y, cos_y) = yaw.sin_cos();
|
||||
|
||||
let abs_sin_yaw = sin_yaw.abs();
|
||||
let abs_sin_pitch = sin_pitch.abs();
|
||||
let abs_cos_yaw = cos_yaw.abs();
|
||||
let x = sin_y * cos_p;
|
||||
let y = -sin_p;
|
||||
let z = cos_y * cos_p;
|
||||
|
||||
let o = abs_sin_yaw * cos_pitch.abs();
|
||||
let ax = x.abs();
|
||||
let ay = y.abs();
|
||||
let az = z.abs();
|
||||
|
||||
if abs_sin_yaw > abs_cos_yaw {
|
||||
if abs_sin_pitch > o {
|
||||
if sin_pitch < 0.0 {
|
||||
Facing::Up
|
||||
} else {
|
||||
Facing::Down
|
||||
}
|
||||
} else if sin_yaw > 0.0 {
|
||||
Facing::East
|
||||
} else {
|
||||
Facing::West
|
||||
}
|
||||
} else if cos_yaw > 0.0 {
|
||||
if ax > ay && ax > az {
|
||||
if x > 0.0 { Facing::East } else { Facing::West }
|
||||
} else if ay > ax && ay > az {
|
||||
if y > 0.0 { Facing::Up } else { Facing::Down }
|
||||
} else if z > 0.0 {
|
||||
Facing::South
|
||||
} else {
|
||||
Facing::North
|
||||
|
||||
Reference in New Issue
Block a user