From 66c65c0df64c08fad26fa0484cb331b4fb33c6a3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 29 Mar 2020 12:53:57 +1100 Subject: [PATCH] make gravity on X direction instead --- src/Camera.c | 5 ++++- src/Entity.c | 10 ++++----- src/Entity.h | 7 +++---- src/EntityComponents.c | 46 ++++++++++++++++++++++-------------------- src/Formats.c | 4 ++-- src/Menus.c | 4 ++-- src/Model.c | 4 ++-- src/Picking.c | 2 +- src/Protocol.c | 2 +- src/Vectors.c | 13 +++++++----- 10 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/Camera.c b/src/Camera.c index 15543c304..ac2a226cb 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -36,17 +36,20 @@ static void PerspectiveCamera_GetProjection(struct Matrix* proj) { } static void PerspectiveCamera_GetView(struct Matrix* mat) { + struct Matrix m; Vec3 pos = Camera.CurrentPos; Vec2 rot = Camera.Active->GetOrientation(); Matrix_LookRot(mat, pos, rot); Matrix_MulBy(mat, &Camera.TiltM); + //Matrix_RotateZ(&m, 90 * MATH_DEG2RAD); + //Matrix_MulBy(mat, &m); } 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 eyePos = Entity_GetEyePosition(p); - float reach = LocalPlayer_Instance.ReachDistance; + float reach = LocalPlayer_Instance.Reach; Picking_CalcPickedBlock(&eyePos, &dir, reach, t); } diff --git a/src/Entity.c b/src/Entity.c index 1608bc77a..c463d192a 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -788,8 +788,8 @@ static void LocalPlayer_HandleInput(float* xMoving, float* zMoving) { } else { if (KeyBind_IsPressed(KEYBIND_FORWARD)) *zMoving -= 0.98f; if (KeyBind_IsPressed(KEYBIND_BACK)) *zMoving += 0.98f; - if (KeyBind_IsPressed(KEYBIND_LEFT)) *xMoving -= 0.98f; - if (KeyBind_IsPressed(KEYBIND_RIGHT)) *xMoving += 0.98f; + if (KeyBind_IsPressed(KEYBIND_LEFT)) *xMoving += 0.98f; + if (KeyBind_IsPressed(KEYBIND_RIGHT)) *xMoving -= 0.98f; p->Physics.Jumping = KeyBind_IsPressed(KEYBIND_JUMP); hacks->Speeding = hacks->Enabled && KeyBind_IsPressed(KEYBIND_SPEED); @@ -835,7 +835,7 @@ static void LocalPlayer_Tick(struct Entity* e, double delta) { } PhysicsComp_UpdateVelocityState(&p->Physics); - headingVelocity = Vec3_RotateY3(xMoving, 0, zMoving, e->Yaw * MATH_DEG2RAD); + headingVelocity = Vec3_RotateY3(0, xMoving, zMoving, e->Yaw * MATH_DEG2RAD); PhysicsComp_PhysicsTick(&p->Physics, headingVelocity); /* Fixes high jump, when holding down a movement key, jump, fly, then let go of fly key */ @@ -889,7 +889,7 @@ static void LocalPlayer_Init(void) { TiltComp_Init(&p->Tilt); p->Base.ModelRestrictedScale = true; - p->ReachDistance = 5.0f; + p->Reach = 5.0f; p->Physics.Hacks = &p->Hacks; p->Physics.Collisions = &p->Collisions; p->Base.VTABLE = &localPlayer_VTABLE; @@ -910,7 +910,7 @@ static void LocalPlayer_Init(void) { static void LocalPlayer_Reset(void) { struct LocalPlayer* p = &LocalPlayer_Instance; - p->ReachDistance = 5.0f; + p->Reach = 5.0f; Vec3_Set(p->Base.Velocity, 0,0,0); p->Physics.JumpVel = 0.42f; p->Physics.ServerJumpVel = 0.42f; diff --git a/src/Entity.h b/src/Entity.h index b71e0c371..190325bd2 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -183,19 +183,18 @@ void NetPlayer_Init(struct NetPlayer* player); extern struct NetPlayer NetPlayers_List[ENTITIES_SELF_ID]; /* Represents the user/player's own entity. */ -struct LocalPlayer { +CC_VAR extern struct LocalPlayer { struct Entity Base; Vec3 Spawn, OldVelocity; - float SpawnYaw, SpawnPitch, ReachDistance; + float SpawnYaw, SpawnPitch, Reach; struct HacksComp Hacks; struct TiltComp Tilt; struct InterpComp Interp; struct CollisionsComp Collisions; struct PhysicsComp Physics; cc_bool _warnedRespawn, _warnedFly, _warnedNoclip; -}; +} LocalPlayer_Instance; -extern struct LocalPlayer LocalPlayer_Instance; /* Returns how high (in blocks) the player can jump. */ float LocalPlayer_JumpHeight(void); /* Interpolates current position and orientation between Interp.Prev and Interp.Next */ diff --git a/src/EntityComponents.c b/src/EntityComponents.c index 9f4c446f4..c79115ac7 100644 --- a/src/EntityComponents.c +++ b/src/EntityComponents.c @@ -749,6 +749,7 @@ static void Collisions_ClipXMin(struct CollisionsComp* comp, struct AABB* blockB comp->Entity->Position.X = blockBB->Min.X - size->X / 2 - COLLISIONS_ADJ; Collisions_ClipX(comp->Entity, size, entityBB, extentBB); comp->HitXMin = true; + comp->Entity->OnGround = true; } } @@ -758,6 +759,7 @@ static void Collisions_ClipXMax(struct CollisionsComp* comp, struct AABB* blockB comp->Entity->Position.X = blockBB->Max.X + size->X / 2 + COLLISIONS_ADJ; Collisions_ClipX(comp->Entity, size, entityBB, extentBB); comp->HitXMax = true; + comp->Entity->OnGround = true; } } @@ -937,25 +939,25 @@ void PhysicsComp_UpdateVelocityState(struct PhysicsComp* comp) { pastJumpPoint = liquidFeet && !liquidRest && (Math_Mod1(entity->Position.Y) >= 0.4f); if (!pastJumpPoint) { comp->CanLiquidJump = true; - entity->Velocity.Y += 0.04f; - if (hacks->Speeding && hacks->CanSpeed) entity->Velocity.Y += 0.04f; - if (hacks->HalfSpeeding && hacks->CanSpeed) entity->Velocity.Y += 0.02f; + entity->Velocity.X += 0.04f; + if (hacks->Speeding && hacks->CanSpeed) entity->Velocity.X += 0.04f; + if (hacks->HalfSpeeding && hacks->CanSpeed) entity->Velocity.X += 0.02f; } else if (pastJumpPoint) { /* either A) climb up solid on side B) jump bob in water */ if (Collisions_HitHorizontal(comp->Collisions)) { - entity->Velocity.Y += touchLava ? 0.30f : 0.13f; + entity->Velocity.X += touchLava ? 0.30f : 0.13f; } else if (comp->CanLiquidJump) { - entity->Velocity.Y += touchLava ? 0.20f : 0.10f; + entity->Velocity.X += touchLava ? 0.20f : 0.10f; } comp->CanLiquidJump = false; } } else if (comp->UseLiquidGravity) { - entity->Velocity.Y += 0.04f; - if (hacks->Speeding && hacks->CanSpeed) entity->Velocity.Y += 0.04f; - if (hacks->HalfSpeeding && hacks->CanSpeed) entity->Velocity.Y += 0.02f; + entity->Velocity.X += 0.04f; + if (hacks->Speeding && hacks->CanSpeed) entity->Velocity.X += 0.04f; + if (hacks->HalfSpeeding && hacks->CanSpeed) entity->Velocity.X += 0.02f; comp->CanLiquidJump = false; } else if (Entity_TouchesAnyRope(entity)) { - entity->Velocity.Y += (hacks->Speeding && hacks->CanSpeed) ? 0.15f : 0.10f; + entity->Velocity.X += (hacks->Speeding && hacks->CanSpeed) ? 0.15f : 0.10f; comp->CanLiquidJump = false; } else if (entity->OnGround) { PhysicsComp_DoNormalJump(comp); @@ -967,9 +969,9 @@ void PhysicsComp_DoNormalJump(struct PhysicsComp* comp) { struct HacksComp* hacks = comp->Hacks; if (comp->JumpVel == 0.0f || hacks->MaxJumps <= 0) return; - entity->Velocity.Y = comp->JumpVel; - if (hacks->Speeding && hacks->CanSpeed) entity->Velocity.Y += comp->JumpVel; - if (hacks->HalfSpeeding && hacks->CanSpeed) entity->Velocity.Y += comp->JumpVel / 2; + entity->Velocity.X = comp->JumpVel; + if (hacks->Speeding && hacks->CanSpeed) entity->Velocity.X += comp->JumpVel; + if (hacks->HalfSpeeding && hacks->CanSpeed) entity->Velocity.X += comp->JumpVel / 2; comp->CanLiquidJump = false; } @@ -995,7 +997,7 @@ static void PhysicsComp_MoveHor(struct PhysicsComp* comp, Vec3 vel, float factor struct Entity* entity; float dist; - dist = Math_SqrtF(vel.X * vel.X + vel.Z * vel.Z); + dist = Math_SqrtF(vel.Y * vel.Y + vel.Z * vel.Z); if (dist < 0.00001f) return; if (dist < 1.0f) dist = 1.0f; @@ -1007,16 +1009,16 @@ static void PhysicsComp_MoveHor(struct PhysicsComp* comp, Vec3 vel, float factor static void PhysicsComp_Move(struct PhysicsComp* comp, Vec3 drag, float gravity, float yMul) { struct Entity* entity = comp->Entity; - entity->Velocity.Y *= yMul; + entity->Velocity.X *= yMul; if (!comp->Hacks->Noclip) { Collisions_MoveAndWallSlide(comp->Collisions); } Vec3_AddBy(&entity->Position, &entity->Velocity); - entity->Velocity.Y /= yMul; + entity->Velocity.X /= yMul; Vec3_Mul3By(&entity->Velocity, &drag); - entity->Velocity.Y -= gravity; + entity->Velocity.X -= gravity; } static void PhysicsComp_MoveFlying(struct PhysicsComp* comp, Vec3 vel, float factor, Vec3 drag, float gravity, float yMul) { @@ -1025,13 +1027,13 @@ static void PhysicsComp_MoveFlying(struct PhysicsComp* comp, Vec3 vel, float fac float yVel; PhysicsComp_MoveHor(comp, vel, factor); - yVel = Math_SqrtF(entity->Velocity.X * entity->Velocity.X + entity->Velocity.Z * entity->Velocity.Z); + yVel = Math_SqrtF(entity->Velocity.Y * entity->Velocity.Y + entity->Velocity.Z * entity->Velocity.Z); /* make horizontal speed the same as vertical speed */ if ((vel.X != 0.0f || vel.Z != 0.0f) && yVel > 0.001f) { entity->Velocity.Y = 0.0f; yMul = 1.0f; - if (hacks->FlyingUp || comp->Jumping) entity->Velocity.Y += yVel; - if (hacks->FlyingDown) entity->Velocity.Y -= yVel; + if (hacks->FlyingUp || comp->Jumping) entity->Velocity.X += yVel; + if (hacks->FlyingDown) entity->Velocity.X -= yVel; } PhysicsComp_Move(comp, drag, gravity, yMul); } @@ -1150,12 +1152,12 @@ void PhysicsComp_PhysicsTick(struct PhysicsComp* comp, Vec3 vel) { if (PhysicsComp_OnIce(entity) && !hacks->Floating) { /* limit components to +-0.25f by rescaling vector to [-0.25, 0.25] */ - if (Math_AbsF(entity->Velocity.X) > 0.25f || Math_AbsF(entity->Velocity.Z) > 0.25f) { - float xScale = Math_AbsF(0.25f / entity->Velocity.X); + if (Math_AbsF(entity->Velocity.Y) > 0.25f || Math_AbsF(entity->Velocity.Z) > 0.25f) { + float xScale = Math_AbsF(0.25f / entity->Velocity.Y); float zScale = Math_AbsF(0.25f / entity->Velocity.Z); float scale = min(xScale, zScale); - entity->Velocity.X *= scale; + entity->Velocity.Y *= scale; entity->Velocity.Z *= scale; } } else if (entity->OnGround || hacks->Flying) { diff --git a/src/Formats.c b/src/Formats.c index eca5a8f9f..f03266bda 100644 --- a/src/Formats.c +++ b/src/Formats.c @@ -547,7 +547,7 @@ static void Cw_Callback_4(struct NbtTag* tag) { if (!IsTag(tag->parent->parent->parent, "Metadata")) return; if (IsTag(tag->parent, "ClickDistance")) { - if (IsTag(tag, "Distance")) { p->ReachDistance = NbtTag_U16(tag) / 32.0f; return; } + if (IsTag(tag, "Distance")) { p->Reach = NbtTag_U16(tag) / 32.0f; return; } } if (IsTag(tag->parent, "EnvWeatherType")) { if (IsTag(tag, "WeatherType")) { Env.Weather = NbtTag_U8(tag); return; } @@ -1130,7 +1130,7 @@ cc_result Cw_Save(struct Stream* stream) { Mem_Copy(tmp, cw_meta_cpe, sizeof(cw_meta_cpe)); { - Stream_SetU16_BE(&tmp[44], (cc_uint16)(LocalPlayer_Instance.ReachDistance * 32)); + Stream_SetU16_BE(&tmp[44], (cc_uint16)(LocalPlayer_Instance.Reach * 32)); tmp[78] = Env.Weather; col = Env.SkyCol; tmp[103] = PackedCol_R(col); tmp[109] = PackedCol_G(col); tmp[115] = PackedCol_B(col); diff --git a/src/Menus.c b/src/Menus.c index 717edd3cb..1d0ce1a24 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -2795,8 +2795,8 @@ void HacksSettingsScreen_Show(void) { /*########################################################################################################################* *----------------------------------------------------MiscOptionsScreen----------------------------------------------------* *#########################################################################################################################*/ -static void MiscOptionsScreen_GetReach(String* v) { String_AppendFloat(v, LocalPlayer_Instance.ReachDistance, 2); } -static void MiscOptionsScreen_SetReach(const String* v) { LocalPlayer_Instance.ReachDistance = Menu_Float(v); } +static void MiscOptionsScreen_GetReach(String* v) { String_AppendFloat(v, LocalPlayer_Instance.Reach, 2); } +static void MiscOptionsScreen_SetReach(const String* v) { LocalPlayer_Instance.Reach = Menu_Float(v); } static void MiscOptionsScreen_GetMusic(String* v) { String_AppendInt(v, Audio_MusicVolume); } static void MiscOptionsScreen_SetMusic(const String* v) { diff --git a/src/Model.c b/src/Model.c index 8645a2b21..cdf2384e8 100644 --- a/src/Model.c +++ b/src/Model.c @@ -41,8 +41,8 @@ void Model_Init(struct Model* model) { model->pushes = true; model->gravity = 0.08f; - Vec3_Set(model->drag, 0.91f, 0.98f, 0.91f); - Vec3_Set(model->groundFriction, 0.6f, 1.0f, 0.6f); + Vec3_Set(model->drag, 0.98f, 0.91f, 0.91f); + Vec3_Set(model->groundFriction, 1.0f, 0.6f, 0.6f); model->maxScale = 2.0f; model->shadowScale = 1.0f; diff --git a/src/Picking.c b/src/Picking.c index edad530e8..6ec956a53 100644 --- a/src/Picking.c +++ b/src/Picking.c @@ -194,7 +194,7 @@ static cc_bool ClipBlock(struct RayTracer* t) { /* Only pick the block if the block is precisely within reach distance. */ lenSq = Vec3_LengthSquared(&scaledDir); - reach = LocalPlayer_Instance.ReachDistance; + reach = LocalPlayer_Instance.Reach; if (lenSq <= reach * reach) { SetAsValid(t); diff --git a/src/Protocol.c b/src/Protocol.c index c768eb97e..212c31574 100644 --- a/src/Protocol.c +++ b/src/Protocol.c @@ -926,7 +926,7 @@ static void CPE_ExtEntry(cc_uint8* data) { } static void CPE_SetClickDistance(cc_uint8* data) { - LocalPlayer_Instance.ReachDistance = Stream_GetU16_BE(data) / 32.0f; + LocalPlayer_Instance.Reach = Stream_GetU16_BE(data) / 32.0f; } static void CPE_CustomBlockLevel(cc_uint8* data) { diff --git a/src/Vectors.c b/src/Vectors.c index 06520117d..6432b58b9 100644 --- a/src/Vectors.c +++ b/src/Vectors.c @@ -205,12 +205,15 @@ void Matrix_PerspectiveOffCenter(struct Matrix* result, float left, float right, } void Matrix_LookRot(struct Matrix* result, Vec3 pos, Vec2 rot) { - struct Matrix rotX, rotY, trans; - Matrix_RotateX(&rotX, rot.Y); - Matrix_RotateY(&rotY, rot.X); + struct Matrix yaw, pit, base, trans; + Matrix_RotateY(&pit, -rot.Y); + Matrix_RotateX(&yaw, rot.X); + Matrix_RotateZ(&base, 90 * MATH_DEG2RAD); Matrix_Translate(&trans, -pos.X, -pos.Y, -pos.Z); - - Matrix_Mul(result, &rotY, &rotX); + + Matrix_Mul(result, &base, &Matrix_Identity); + Matrix_Mul(result, &yaw, result); + Matrix_Mul(result, &pit, result); Matrix_Mul(result, &trans, result); }