Adjust picked position to account for camera vertical fall tilt when not running in classic mode (Thanks Goodly)

This commit is contained in:
UnknownShadow200 2022-09-29 08:52:55 +10:00
parent 20a40fea27
commit 3c9774fe4f
5 changed files with 18 additions and 8 deletions

View File

@ -39,7 +39,7 @@ static void PerspectiveCamera_GetView(struct Matrix* mat) {
static void PerspectiveCamera_GetPickedBlock(struct RayTracer* t) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec3 dir = Vec3_GetDirVector(p->Yaw * MATH_DEG2RAD, p->Pitch * MATH_DEG2RAD);
Vec3 dir = Vec3_GetDirVector(p->Yaw * MATH_DEG2RAD, p->Pitch * MATH_DEG2RAD + Camera.TiltPitch);
Vec3 eyePos = Entity_GetEyePosition(p);
float reach = LocalPlayer_Instance.ReachDistance;
Picking_CalcPickedBlock(&eyePos, &dir, reach, t);
@ -110,8 +110,12 @@ static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
struct Entity* e = &p->Base;
struct Matrix tiltY, velX;
float vel;
if (!Game_ViewBobbing) { Camera.TiltM = Matrix_Identity; return; }
float vel, fall;
if (!Game_ViewBobbing) {
Camera.TiltM = Matrix_Identity;
Camera.TiltPitch = 0.0f;
return;
}
Matrix_RotateZ(&Camera.TiltM, -p->Tilt.TiltX * e->Anim.BobStrength);
Matrix_RotateX(&tiltY, Math_AbsF(p->Tilt.TiltY) * 3.0f * e->Anim.BobStrength);
@ -120,9 +124,12 @@ static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
Camera.BobbingHor = (e->Anim.BobbingHor * 0.3f) * e->Anim.BobStrength;
Camera.BobbingVer = (e->Anim.BobbingVer * 0.6f) * e->Anim.BobStrength;
vel = Math_Lerp(p->OldVelocity.Y + 0.08f, e->Velocity.Y + 0.08f, t);
Matrix_RotateX(&velX, -vel * 0.05f * p->Tilt.VelTiltStrength / velTiltScale);
vel = Math_Lerp(p->OldVelocity.Y + 0.08f, e->Velocity.Y + 0.08f, t);
fall = -vel * 0.05f * p->Tilt.VelTiltStrength / velTiltScale;
Matrix_RotateX(&velX, fall);
Matrix_MulBy(&Camera.TiltM, &velX);
if (!Game_ClassicMode) Camera.TiltPitch = fall;
}

View File

@ -34,6 +34,8 @@ CC_VAR extern struct _CameraData {
float Mass;
/* Field of view of the camera */
int Fov, DefaultFov, ZoomFov;
float TiltPitch;
} Camera;
struct Camera {

View File

@ -478,7 +478,7 @@ static void Entity_CheckSkin(struct Entity* e) {
if (!e->SkinFetchState) {
first = Entity_FirstOtherWithSameSkinAndFetchedSkin(e);
flags = e == &LocalPlayer_Instance ? HTTP_FLAG_NOCACHE : 0;
flags = e == &LocalPlayer_Instance.Base ? HTTP_FLAG_NOCACHE : 0;
if (!first) {
e->_skinReqID = Http_AsyncGetSkin(&skin, flags);

View File

@ -63,8 +63,6 @@ CC_VAR extern struct _DisplayData {
int Display_ScaleX(int x);
/* Scales the given Y coordinate from 96 dpi to current display dpi. */
int Display_ScaleY(int y);
#define Display_CentreX(width) (DisplayInfo.X + (DisplayInfo.Width - width) / 2)
#define Display_CentreY(height) (DisplayInfo.Y + (DisplayInfo.Height - height) / 2)
/* Data for the game/launcher window. */
CC_VAR extern struct _WinData {

View File

@ -7,6 +7,9 @@
struct _DisplayData DisplayInfo;
struct _WinData WindowInfo;
#define Display_CentreX(width) (DisplayInfo.X + (DisplayInfo.Width - width) / 2)
#define Display_CentreY(height) (DisplayInfo.Y + (DisplayInfo.Height - height) / 2)
int Display_ScaleX(int x) { return (int)(x * DisplayInfo.ScaleX); }
int Display_ScaleY(int y) { return (int)(y * DisplayInfo.ScaleY); }