HeadX -> Pitch and HeadY -> Yaw

This commit is contained in:
UnknownShadow200 2019-11-26 22:37:19 +11:00
parent 508477b0c6
commit d3363f192d
13 changed files with 119 additions and 119 deletions

View File

@ -577,7 +577,7 @@ static int RotateVertical(String* name, int offset) {
static int RotateFence(String* name, int offset) {
float yaw;
/* Fence type blocks */
yaw = LocalPlayer_Instance.Base.HeadY;
yaw = LocalPlayer_Instance.Base.Yaw;
yaw = LocationUpdate_Clamp(yaw);
if (yaw < 45.0f || (yaw >= 135.0f && yaw < 225.0f) || yaw > 315.0f) {
@ -604,7 +604,7 @@ static int RotatePillar(String* name, int offset) {
static int RotateDirection(String* name, int offset) {
float yaw;
yaw = LocalPlayer_Instance.Base.HeadY;
yaw = LocalPlayer_Instance.Base.Yaw;
yaw = LocationUpdate_Clamp(yaw);
if (yaw >= 45.0f && yaw < 135.0f) {

View File

@ -42,7 +42,7 @@ static void PerspectiveCamera_GetView(struct Matrix* mat) {
static void PerspectiveCamera_GetPickedBlock(struct PickedPos* pos) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec3 dir = Vec3_GetDirVector(p->HeadY * MATH_DEG2RAD, p->HeadX * MATH_DEG2RAD);
Vec3 dir = Vec3_GetDirVector(p->Yaw * MATH_DEG2RAD, p->Pitch * MATH_DEG2RAD);
Vec3 eyePos = Entity_GetEyePosition(p);
float reach = LocalPlayer_Instance.ReachDistance;
Picking_CalculatePickedBlock(eyePos, dir, reach, pos);
@ -77,7 +77,7 @@ static void PerspectiveCamera_UpdateMouseRotation(double delta) {
struct Entity* e = &p->Base;
struct LocationUpdate update;
float headY, headX;
float yaw, pitch;
Vec2 rot = PerspectiveCamera_GetMouseDelta(delta);
if (Key_IsAltPressed() && Camera.Active->isThirdPerson) {
@ -85,13 +85,13 @@ static void PerspectiveCamera_UpdateMouseRotation(double delta) {
return;
}
headY = p->Interp.Next.HeadY + rot.X;
headX = p->Interp.Next.HeadX + rot.Y;
LocationUpdate_MakeOri(&update, headY, headX);
yaw = p->Interp.Next.Yaw + rot.X;
pitch = p->Interp.Next.Pitch + rot.Y;
LocationUpdate_MakeOri(&update, yaw, pitch);
/* Need to make sure we don't cross the vertical axes, because that gets weird. */
if (update.HeadX >= 90.0f && update.HeadX <= 270.0f) {
update.HeadX = p->Interp.Next.HeadX < 180.0f ? 90.0f : 270.0f;
if (update.Pitch >= 90.0f && update.Pitch <= 270.0f) {
update.Pitch = p->Interp.Next.Pitch < 180.0f ? 90.0f : 270.0f;
}
e->VTABLE->SetLocation(e, &update, false);
}
@ -130,19 +130,19 @@ static void PerspectiveCamera_CalcViewBobbing(float t, float velTiltScale) {
static Vec2 FirstPersonCamera_GetOrientation(void) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec2 v;
v.X = p->HeadY * MATH_DEG2RAD; v.Y = p->HeadX * MATH_DEG2RAD;
v.X = p->Yaw * MATH_DEG2RAD; v.Y = p->Pitch * MATH_DEG2RAD;
return v;
}
static Vec3 FirstPersonCamera_GetPosition(float t) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec3 camPos = Entity_GetEyePosition(p);
float headY = p->HeadY * MATH_DEG2RAD;
float yaw = p->Yaw * MATH_DEG2RAD;
PerspectiveCamera_CalcViewBobbing(t, 1);
camPos.Y += Camera.BobbingVer;
camPos.X += Camera.BobbingHor * (float)Math_Cos(headY);
camPos.Z += Camera.BobbingHor * (float)Math_Sin(headY);
camPos.X += Camera.BobbingHor * (float)Math_Cos(yaw);
camPos.Z += Camera.BobbingHor * (float)Math_Sin(yaw);
return camPos;
}
@ -165,7 +165,7 @@ float dist_third = 3.0f, dist_forward = 3.0f;
static Vec2 ThirdPersonCamera_GetOrientation(void) {
struct Entity* p = &LocalPlayer_Instance.Base;
Vec2 v;
v.X = p->HeadY * MATH_DEG2RAD; v.Y = p->HeadX * MATH_DEG2RAD;
v.X = p->Yaw * MATH_DEG2RAD; v.Y = p->Pitch * MATH_DEG2RAD;
if (cam_isForwardThird) { v.X += MATH_PI; v.Y = -v.Y; }
v.X += cam_rotOffset.X * MATH_DEG2RAD;

View File

@ -33,11 +33,11 @@ float LocationUpdate_Clamp(float degrees) {
}
static struct LocationUpdate loc_empty;
void LocationUpdate_MakeOri(struct LocationUpdate* update, float rotY, float headX) {
void LocationUpdate_MakeOri(struct LocationUpdate* update, float yaw, float pitch) {
*update = loc_empty;
update->Flags = LOCATIONUPDATE_FLAG_HEADX | LOCATIONUPDATE_FLAG_HEADY;
update->HeadX = LocationUpdate_Clamp(headX);
update->HeadY = LocationUpdate_Clamp(rotY);
update->Flags = LOCATIONUPDATE_FLAG_PITCH | LOCATIONUPDATE_FLAG_YAW;
update->Pitch = LocationUpdate_Clamp(pitch);
update->Yaw = LocationUpdate_Clamp(yaw);
}
void LocationUpdate_MakePos(struct LocationUpdate* update, Vec3 pos, cc_bool rel) {
@ -47,11 +47,11 @@ void LocationUpdate_MakePos(struct LocationUpdate* update, Vec3 pos, cc_bool rel
update->RelativePos = rel;
}
void LocationUpdate_MakePosAndOri(struct LocationUpdate* update, Vec3 pos, float rotY, float headX, cc_bool rel) {
void LocationUpdate_MakePosAndOri(struct LocationUpdate* update, Vec3 pos, float yaw, float pitch, cc_bool rel) {
*update = loc_empty;
update->Flags = LOCATIONUPDATE_FLAG_POS | LOCATIONUPDATE_FLAG_HEADX | LOCATIONUPDATE_FLAG_HEADY;
update->HeadX = LocationUpdate_Clamp(headX);
update->HeadY = LocationUpdate_Clamp(rotY);
update->Flags = LOCATIONUPDATE_FLAG_POS | LOCATIONUPDATE_FLAG_PITCH | LOCATIONUPDATE_FLAG_YAW;
update->Pitch = LocationUpdate_Clamp(pitch);
update->Yaw = LocationUpdate_Clamp(yaw);
update->Pos = pos;
update->RelativePos = rel;
}
@ -633,7 +633,7 @@ void Entities_Remove(EntityID id) {
EntityID Entities_GetClosest(struct Entity* src) {
Vec3 eyePos = Entity_GetEyePosition(src);
Vec3 dir = Vec3_GetDirVector(src->HeadY * MATH_DEG2RAD, src->HeadX * MATH_DEG2RAD);
Vec3 dir = Vec3_GetDirVector(src->Yaw * MATH_DEG2RAD, src->Pitch * MATH_DEG2RAD);
float closestDist = MATH_POS_INF;
EntityID targetId = ENTITIES_SELF_ID;
@ -832,7 +832,7 @@ static void LocalPlayer_Tick(struct Entity* e, double delta) {
}
PhysicsComp_UpdateVelocityState(&p->Physics);
headingVelocity = Vec3_RotateY3(xMoving, 0, zMoving, e->HeadY * MATH_DEG2RAD);
headingVelocity = Vec3_RotateY3(xMoving, 0, 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 */
@ -956,7 +956,7 @@ static void LocalPlayer_DoRespawn(void) {
}
spawn.Y += 2.0f/16.0f;
LocationUpdate_MakePosAndOri(&update, spawn, p->SpawnRotY, p->SpawnHeadX, false);
LocationUpdate_MakePosAndOri(&update, spawn, p->SpawnYaw, p->SpawnPitch, false);
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
Vec3_Set(p->Base.Velocity, 0,0,0);
@ -996,8 +996,8 @@ static cc_bool LocalPlayer_HandleSetSpawn(void) {
p->Spawn.Z = Math_Floor(p->Base.Position.Z) + 0.5f;
}
p->SpawnRotY = p->Base.RotY;
p->SpawnHeadX = p->Base.HeadX;
p->SpawnYaw = p->Base.Yaw;
p->SpawnPitch = p->Base.Pitch;
}
return LocalPlayer_HandleRespawn();
}

View File

@ -31,14 +31,14 @@ extern const char* const ShadowMode_Names[SHADOW_MODE_COUNT];
enum EntityType { ENTITY_TYPE_NONE, ENTITY_TYPE_PLAYER };
#define LOCATIONUPDATE_FLAG_POS 0x01
#define LOCATIONUPDATE_FLAG_HEADX 0x02
#define LOCATIONUPDATE_FLAG_HEADY 0x04
#define LOCATIONUPDATE_FLAG_PITCH 0x02
#define LOCATIONUPDATE_FLAG_YAW 0x04
#define LOCATIONUPDATE_FLAG_ROTX 0x08
#define LOCATIONUPDATE_FLAG_ROTZ 0x10
/* Represents a location update for an entity. Can be a relative position, full position, and/or an orientation update. */
struct LocationUpdate {
Vec3 Pos;
float HeadX, HeadY, RotX, RotZ;
float Pitch, Yaw, RotX, RotZ;
cc_uint8 Flags;
cc_bool RelativePos;
};
@ -46,11 +46,11 @@ struct LocationUpdate {
/* Clamps the given angle so it lies between [0, 360). */
float LocationUpdate_Clamp(float degrees);
/* Makes a location update only containing yaw and pitch. */
void LocationUpdate_MakeOri(struct LocationUpdate* update, float rotY, float headX);
void LocationUpdate_MakeOri(struct LocationUpdate* update, float yaw, float pitch);
/* Makes a location update only containing position */
void LocationUpdate_MakePos(struct LocationUpdate* update, Vec3 pos, cc_bool rel);
/* Makes a location update containing position, yaw and pitch. */
void LocationUpdate_MakePosAndOri(struct LocationUpdate* update, Vec3 pos, float rotY, float headX, cc_bool rel);
void LocationUpdate_MakePosAndOri(struct LocationUpdate* update, Vec3 pos, float yaw, float pitch, cc_bool rel);
struct Entity;
struct EntityVTABLE {
@ -71,7 +71,7 @@ struct EntityVTABLE {
struct Entity {
struct EntityVTABLE* VTABLE;
Vec3 Position;
float HeadX, HeadY, RotX, RotY, RotZ;
float Pitch, Yaw, RotX, RotY, RotZ;
Vec3 Velocity;
struct Model* Model;
@ -185,7 +185,7 @@ extern struct NetPlayer NetPlayers_List[ENTITIES_SELF_ID];
struct LocalPlayer {
struct Entity Base;
Vec3 Spawn, OldVelocity;
float SpawnRotY, SpawnHeadX, ReachDistance;
float SpawnYaw, SpawnPitch, ReachDistance;
struct HacksComp Hacks;
struct TiltComp Tilt;
struct InterpComp Interp;

View File

@ -308,11 +308,11 @@ void InterpComp_LerpAngles(struct InterpComp* interp, struct Entity* e, float t)
struct InterpState* prev = &interp->Prev;
struct InterpState* next = &interp->Next;
e->HeadX = Math_LerpAngle(prev->HeadX, next->HeadX, t);
e->HeadY = Math_LerpAngle(prev->HeadY, next->HeadY, t);
e->RotX = Math_LerpAngle(prev->RotX, next->RotX, t);
e->Pitch = Math_LerpAngle(prev->Pitch, next->Pitch, t);
e->Yaw = Math_LerpAngle(prev->Yaw, next->Yaw, t);
e->RotX = Math_LerpAngle(prev->RotX, next->RotX, t);
e->RotY = Math_LerpAngle(interp->PrevRotY, interp->NextRotY, t);
e->RotZ = Math_LerpAngle(prev->RotZ, next->RotZ, t);
e->RotZ = Math_LerpAngle(prev->RotZ, next->RotZ, t);
}
static void InterpComp_SetPos(struct InterpState* state, struct LocationUpdate* update) {
@ -350,12 +350,12 @@ void NetInterpComp_SetLocation(struct NetInterpComp* interp, struct LocationUpda
if (flags & LOCATIONUPDATE_FLAG_POS) InterpComp_SetPos(cur, update);
if (flags & LOCATIONUPDATE_FLAG_ROTX) cur->RotX = update->RotX;
if (flags & LOCATIONUPDATE_FLAG_ROTZ) cur->RotZ = update->RotZ;
if (flags & LOCATIONUPDATE_FLAG_HEADX) cur->HeadX = update->HeadX;
if (flags & LOCATIONUPDATE_FLAG_HEADY) cur->HeadY = update->HeadY;
if (flags & LOCATIONUPDATE_FLAG_PITCH) cur->Pitch = update->Pitch;
if (flags & LOCATIONUPDATE_FLAG_YAW) cur->Yaw = update->Yaw;
if (!interpolate) {
interp->Prev = *cur; interp->PrevRotY = cur->HeadY;
interp->Next = *cur; interp->NextRotY = cur->HeadY;
interp->Prev = *cur; interp->PrevRotY = cur->Yaw;
interp->Next = *cur; interp->NextRotY = cur->Yaw;
interp->RotYCount = 0; interp->StatesCount = 0;
} else {
/* Smoother interpolation by also adding midpoint. */
@ -363,15 +363,15 @@ void NetInterpComp_SetLocation(struct NetInterpComp* interp, struct LocationUpda
Vec3_Lerp(&mid.Pos, &last.Pos, &cur->Pos, 0.5f);
mid.RotX = Math_LerpAngle(last.RotX, cur->RotX, 0.5f);
mid.RotZ = Math_LerpAngle(last.RotZ, cur->RotZ, 0.5f);
mid.HeadX = Math_LerpAngle(last.HeadX, cur->HeadX, 0.5f);
mid.HeadY = Math_LerpAngle(last.HeadY, cur->HeadY, 0.5f);
mid.Pitch = Math_LerpAngle(last.Pitch, cur->Pitch, 0.5f);
mid.Yaw = Math_LerpAngle(last.Yaw, cur->Yaw, 0.5f);
NetInterpComp_AddState(interp, mid);
NetInterpComp_AddState(interp, *cur);
/* Head rotation lags behind body a tiny bit */
InterpComp_AddRotY((struct InterpComp*)interp, Math_LerpAngle(last.HeadY, cur->HeadY, 0.33333333f));
InterpComp_AddRotY((struct InterpComp*)interp, Math_LerpAngle(last.HeadY, cur->HeadY, 0.66666667f));
InterpComp_AddRotY((struct InterpComp*)interp, Math_LerpAngle(last.HeadY, cur->HeadY, 1.00000000f));
/* Body rotation lags behind head a tiny bit */
InterpComp_AddRotY((struct InterpComp*)interp, Math_LerpAngle(last.Yaw, cur->Yaw, 0.33333333f));
InterpComp_AddRotY((struct InterpComp*)interp, Math_LerpAngle(last.Yaw, cur->Yaw, 0.66666667f));
InterpComp_AddRotY((struct InterpComp*)interp, Math_LerpAngle(last.Yaw, cur->Yaw, 1.00000000f));
}
}
@ -409,11 +409,11 @@ void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdat
if (!interpolate) { prev->Pos = next->Pos; entity->Position = next->Pos; }
}
if (flags & LOCATIONUPDATE_FLAG_HEADX) {
LocalInterpComp_Angle(&prev->HeadX, &next->HeadX, update->HeadX, interpolate);
if (flags & LOCATIONUPDATE_FLAG_PITCH) {
LocalInterpComp_Angle(&prev->Pitch, &next->Pitch, update->Pitch, interpolate);
}
if (flags & LOCATIONUPDATE_FLAG_HEADY) {
LocalInterpComp_Angle(&prev->HeadY, &next->HeadY, update->HeadY, interpolate);
if (flags & LOCATIONUPDATE_FLAG_YAW) {
LocalInterpComp_Angle(&prev->Yaw, &next->Yaw, update->Yaw, interpolate);
}
if (flags & LOCATIONUPDATE_FLAG_ROTX) {
LocalInterpComp_Angle(&prev->RotX, &next->RotX, update->RotX, interpolate);
@ -422,16 +422,16 @@ void LocalInterpComp_SetLocation(struct InterpComp* interp, struct LocationUpdat
LocalInterpComp_Angle(&prev->RotZ, &next->RotZ, update->RotZ, interpolate);
}
if (flags & LOCATIONUPDATE_FLAG_HEADY) {
if (flags & LOCATIONUPDATE_FLAG_YAW) {
if (!interpolate) {
interp->NextRotY = update->HeadY;
entity->RotY = update->HeadY;
interp->NextRotY = update->Yaw;
entity->RotY = update->Yaw;
interp->RotYCount = 0;
} else {
/* Body Y rotation lags slightly behind */
InterpComp_AddRotY(interp, Math_LerpAngle(prev->HeadY, next->HeadY, 0.33333333f));
InterpComp_AddRotY(interp, Math_LerpAngle(prev->HeadY, next->HeadY, 0.66666667f));
InterpComp_AddRotY(interp, Math_LerpAngle(prev->HeadY, next->HeadY, 1.00000000f));
InterpComp_AddRotY(interp, Math_LerpAngle(prev->Yaw, next->Yaw, 0.33333333f));
InterpComp_AddRotY(interp, Math_LerpAngle(prev->Yaw, next->Yaw, 0.66666667f));
InterpComp_AddRotY(interp, Math_LerpAngle(prev->Yaw, next->Yaw, 1.00000000f));
interp->NextRotY = interp->RotYStates[0];
}

View File

@ -76,7 +76,7 @@ void HacksComp_RecheckFlags(struct HacksComp* hacks);
void HacksComp_Update(struct HacksComp* hacks);
/* Represents a position and orientation state */
struct InterpState { Vec3 Pos; float HeadX, HeadY, RotX, RotZ; };
struct InterpState { Vec3 Pos; float Pitch, Yaw, RotX, RotZ; };
#define InterpComp_Layout \
struct InterpState Prev, Next; float PrevRotY, NextRotY; int RotYCount; float RotYStates[15];

View File

@ -76,7 +76,7 @@ void Map_LoadFrom(const String* path) {
World_SetNewMap(World.Blocks, World.Width, World.Height, World.Length);
Event_RaiseVoid(&WorldEvents.MapLoaded);
LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnRotY, p->SpawnHeadX, false);
LocationUpdate_MakePosAndOri(&update, p->Spawn, p->SpawnYaw, p->SpawnPitch, false);
p->Base.VTABLE->SetLocation(&p->Base, &update, false);
}
@ -184,8 +184,8 @@ cc_result Lvl_Load(struct Stream* stream) {
p->Spawn.X = Stream_GetU16_LE(&header[8]);
p->Spawn.Z = Stream_GetU16_LE(&header[10]);
p->Spawn.Y = Stream_GetU16_LE(&header[12]);
p->SpawnRotY = Math_Packed2Deg(header[14]);
p->SpawnHeadX = Math_Packed2Deg(header[15]);
p->SpawnYaw = Math_Packed2Deg(header[14]);
p->SpawnPitch = Math_Packed2Deg(header[15]);
/* (2) pervisit, perbuild permissions */
if ((res = Map_ReadBlocks(&compStream))) return res;
@ -259,8 +259,8 @@ cc_result Fcm_Load(struct Stream* stream) {
p->Spawn.X = ((int)Stream_GetU32_LE(&header[11])) / 32.0f;
p->Spawn.Y = ((int)Stream_GetU32_LE(&header[15])) / 32.0f;
p->Spawn.Z = ((int)Stream_GetU32_LE(&header[19])) / 32.0f;
p->SpawnRotY = Math_Packed2Deg(header[23]);
p->SpawnHeadX = Math_Packed2Deg(header[24]);
p->SpawnYaw = Math_Packed2Deg(header[23]);
p->SpawnPitch = Math_Packed2Deg(header[24]);
/* header[25] (4) date modified */
/* header[29] (4) date created */
@ -527,8 +527,8 @@ static void Cw_Callback_2(struct NbtTag* tag) {
if (IsTag(tag, "X")) { p->Spawn.X = NbtTag_I16(tag); return; }
if (IsTag(tag, "Y")) { p->Spawn.Y = NbtTag_I16(tag); return; }
if (IsTag(tag, "Z")) { p->Spawn.Z = NbtTag_I16(tag); return; }
if (IsTag(tag, "H")) { p->SpawnRotY = Math_Packed2Deg(NbtTag_U8(tag)); return; }
if (IsTag(tag, "P")) { p->SpawnHeadX = Math_Packed2Deg(NbtTag_U8(tag)); return; }
if (IsTag(tag, "H")) { p->SpawnYaw = Math_Packed2Deg(NbtTag_U8(tag)); return; }
if (IsTag(tag, "P")) { p->SpawnPitch = Math_Packed2Deg(NbtTag_U8(tag)); return; }
}
static BlockID cw_curID;
@ -1110,8 +1110,8 @@ cc_result Cw_Save(struct Stream* stream) {
Stream_SetU16_BE(&tmp[89], (cc_uint16)p->Base.Position.X);
Stream_SetU16_BE(&tmp[95], (cc_uint16)p->Base.Position.Y);
Stream_SetU16_BE(&tmp[101], (cc_uint16)p->Base.Position.Z);
tmp[107] = Math_Deg2Packed(p->SpawnRotY);
tmp[112] = Math_Deg2Packed(p->SpawnHeadX);
tmp[107] = Math_Deg2Packed(p->SpawnYaw);
tmp[112] = Math_Deg2Packed(p->SpawnPitch);
}
if ((res = Stream_Write(stream, tmp, sizeof(cw_begin)))) return res;
if ((res = Stream_Write(stream, World.Blocks, World.Volume))) return res;

View File

@ -69,8 +69,8 @@ static void HeldBlockRenderer_ResetHeldState(void) {
held_entity.Position.Y -= Camera.BobbingVer;
held_entity.Position.Z -= Camera.BobbingHor;
held_entity.HeadY = -45.0f; held_entity.RotY = -45.0f;
held_entity.HeadX = 0.0f; held_entity.RotX = 0.0f;
held_entity.Yaw = -45.0f; held_entity.RotY = -45.0f;
held_entity.Pitch = 0.0f; held_entity.RotX = 0.0f;
held_entity.ModelBlock = held_block;
held_entity.SkinType = p->SkinType;
@ -122,7 +122,7 @@ static void HeldBlockRenderer_DigAnimation(void) {
sinHalfCircleWeird = Math_Sin(t * t * MATH_PI);
held_entity.RotY -= (float)Math_Sin(sqrtLerpPI) * 80.0f;
held_entity.HeadY -= (float)Math_Sin(sqrtLerpPI) * 80.0f;
held_entity.Yaw -= (float)Math_Sin(sqrtLerpPI) * 80.0f;
held_entity.RotX += (float)sinHalfCircleWeird * 20.0f;
}
@ -136,17 +136,17 @@ static void HeldBlockRenderer_ResetAnim(cc_bool setLastHeld, double period) {
static PackedCol HeldBlockRenderer_GetCol(struct Entity* entity) {
struct Entity* player;
PackedCol col;
float adjHeadX, t, scale;
float adjPitch, t, scale;
player = &LocalPlayer_Instance.Base;
col = player->VTABLE->GetCol(player);
/* Adjust pitch so angle when looking straight down is 0. */
adjHeadX = player->HeadX - 90.0f;
if (adjHeadX < 0.0f) adjHeadX += 360.0f;
adjPitch = player->Pitch - 90.0f;
if (adjPitch < 0.0f) adjPitch += 360.0f;
/* Adjust colour so held block is brighter when looking straight up */
t = Math_AbsF(adjHeadX - 180.0f) / 180.0f;
t = Math_AbsF(adjPitch - 180.0f) / 180.0f;
scale = Math_Lerp(0.9f, 0.7f, t);
return PackedCol_Scale(col, scale);
}

View File

@ -436,7 +436,7 @@ void MapRenderer_RefreshBorders(int maxHeight) {
#define CHUNK_TARGET_TIME ((1.0/30) + 0.01)
static int chunksTarget = 12;
static Vec3 lastCamPos;
static float lastHeadY, lastHeadX;
static float lastYaw, lastPitch;
/* Max distance from camera that chunks are rendered within */
/* This may differ from the view distance configured by the user */
static int renderDistSquared;
@ -535,15 +535,15 @@ static void MapRenderer_UpdateChunks(double delta) {
p = &LocalPlayer_Instance;
samePos = Vec3_Equals(&Camera.CurrentPos, &lastCamPos)
&& p->Base.HeadX == lastHeadX && p->Base.HeadY == lastHeadY;
&& p->Base.Pitch == lastPitch && p->Base.Yaw == lastYaw;
renderChunksCount = samePos ?
MapRenderer_UpdateChunksStill(&chunkUpdates) :
MapRenderer_UpdateChunksAndVisibility(&chunkUpdates);
lastCamPos = Camera.CurrentPos;
lastHeadX = p->Base.HeadX;
lastHeadY = p->Base.HeadY;
lastPitch = p->Base.Pitch;
lastYaw = p->Base.Yaw;
if (!samePos || chunkUpdates) {
MapRenderer_ResetPartFlags();

View File

@ -134,7 +134,7 @@ void Model_SetupState(struct Model* model, struct Entity* entity) {
Models.Cols[3] = Models.Cols[2];
Models.Cols[5] = Models.Cols[4];
yawDelta = entity->HeadY - entity->RotY;
yawDelta = entity->Yaw - entity->RotY;
Models.cosHead = (float)Math_Cos(yawDelta * MATH_DEG2RAD);
Models.sinHead = (float)Math_Sin(yawDelta * MATH_DEG2RAD);
@ -451,7 +451,7 @@ static void HumanModel_DrawModelSet(struct Entity* entity, struct ModelSet* mode
type = Models.skinType;
set = &model->Limbs[type & 0x3];
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &model->Head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &model->Head, true);
Model_DrawPart(&model->Torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, entity->Anim.LeftLegZ, &set->LeftLeg, false);
Model_DrawRotate(entity->Anim.RightLegX, 0, entity->Anim.RightLegZ, &set->RightLeg, false);
@ -473,7 +473,7 @@ static void HumanModel_DrawModelSet(struct Entity* entity, struct ModelSet* mode
Model_DrawRotate(entity->Anim.RightArmX, 0, entity->Anim.RightArmZ, &set->RightArmLayer, false);
Models.Rotation = ROTATE_ORDER_ZYX;
}
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &model->Hat, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &model->Hat, true);
Model_UpdateVB();
}
@ -808,9 +808,9 @@ static void HeadModel_Draw(struct Entity* entity) {
Model_ApplyTexture(entity);
part = human_set.Head; part.RotY += 4.0f/16.0f;
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &part, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &part, true);
part = human_set.Hat; part.RotY += 4.0f/16.0f;
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &part, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &part, true);
Model_UpdateVB();
}
@ -904,9 +904,9 @@ static void ChickenModel_Draw(struct Entity* entity) {
int i;
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &chicken_head, true);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &chicken_wattle, true);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &chicken_beak, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &chicken_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &chicken_wattle, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &chicken_beak, true);
Model_DrawPart(&chicken_torso);
Model_DrawRotate(0, 0, -Math_AbsF(entity->Anim.LeftArmX), &chicken_leftWing, false);
@ -988,7 +988,7 @@ static void CreeperModel_MakeParts(void) {
static void CreeperModel_Draw(struct Entity* entity) {
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &creeper_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &creeper_head, true);
Model_DrawPart(&creeper_torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &creeper_leftLegFront, false);
@ -1066,7 +1066,7 @@ static void PigModel_MakeParts(void) {
static void PigModel_Draw(struct Entity* entity) {
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &pig_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &pig_head, true);
Model_DrawPart(&pig_torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &pig_leftLegFront, false);
@ -1190,7 +1190,7 @@ static void SheepModel_MakeParts(void) {
static void FurlessModel_Draw(struct Entity* entity) {
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &sheep_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &sheep_head, true);
Model_DrawPart(&sheep_torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &sheep_leftLegFront, false);
@ -1203,7 +1203,7 @@ static void FurlessModel_Draw(struct Entity* entity) {
static void SheepModel_Draw(struct Entity* entity) {
FurlessModel_Draw(entity);
Gfx_BindTexture(fur_tex.TexID);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &fur_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &fur_head, true);
Model_DrawPart(&fur_torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &fur_leftLegFront, false);
@ -1290,7 +1290,7 @@ static void SkeletonModel_MakeParts(void) {
static void SkeletonModel_Draw(struct Entity* entity) {
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &skeleton_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &skeleton_head, true);
Model_DrawPart(&skeleton_torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &skeleton_leftLeg, false);
@ -1370,7 +1370,7 @@ static void SpiderModel_MakeParts(void) {
static void SpiderModel_Draw(struct Entity* entity) {
float rotX, rotY, rotZ;
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &spider_head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &spider_head, true);
Model_DrawPart(&spider_link);
Model_DrawPart(&spider_end);
@ -1418,7 +1418,7 @@ static struct Model* SpiderModel_GetInstance(void) {
static void ZombieModel_Draw(struct Entity* entity) {
Model_ApplyTexture(entity);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &human_set.Head, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &human_set.Head, true);
Model_DrawPart(&human_set.Torso);
Model_DrawRotate(entity->Anim.LeftLegX, 0, 0, &human_set.Limbs[0].LeftLeg, false);
@ -1426,7 +1426,7 @@ static void ZombieModel_Draw(struct Entity* entity) {
Model_DrawRotate(90.0f * MATH_DEG2RAD, 0, entity->Anim.LeftArmZ, &human_set.Limbs[0].LeftArm, false);
Model_DrawRotate(90.0f * MATH_DEG2RAD, 0, entity->Anim.RightArmZ, &human_set.Limbs[0].RightArm, false);
Model_DrawRotate(-entity->HeadX * MATH_DEG2RAD, 0, 0, &human_set.Hat, true);
Model_DrawRotate(-entity->Pitch * MATH_DEG2RAD, 0, 0, &human_set.Hat, true);
Model_UpdateVB();
}

View File

@ -172,8 +172,8 @@ static void Protocol_AddEntity(cc_uint8* data, EntityID id, const String* displa
if (id != ENTITIES_SELF_ID) return;
p->Spawn = p->Base.Position;
p->SpawnRotY = p->Base.HeadY;
p->SpawnHeadX = p->Base.HeadX;
p->SpawnYaw = p->Base.Yaw;
p->SpawnPitch = p->Base.Pitch;
}
void Protocol_RemoveEntity(EntityID id) {
@ -314,7 +314,7 @@ void Classic_SendChat(const String* text, cc_bool partial) {
Server.SendData(data, 66);
}
void Classic_WritePosition(Vec3 pos, float rotY, float headX) {
void Classic_WritePosition(Vec3 pos, float rotY, float pitch) {
BlockID payload;
int x, y, z;
@ -338,7 +338,7 @@ void Classic_WritePosition(Vec3 pos, float rotY, float headX) {
}
*data++ = Math_Deg2Packed(rotY);
*data++ = Math_Deg2Packed(headX);
*data++ = Math_Deg2Packed(pitch);
}
Server.WriteBuffer = data;
}
@ -573,15 +573,15 @@ static void Classic_RelPosAndOrientationUpdate(cc_uint8* data) {
struct LocationUpdate update;
EntityID id = *data++;
Vec3 pos;
float rotY, headX;
float rotY, pitch;
pos.X = (cc_int8)(*data++) / 32.0f;
pos.Y = (cc_int8)(*data++) / 32.0f;
pos.Z = (cc_int8)(*data++) / 32.0f;
rotY = Math_Packed2Deg(*data++);
headX = Math_Packed2Deg(*data++);
pitch = Math_Packed2Deg(*data++);
LocationUpdate_MakePosAndOri(&update, pos, rotY, headX, true);
LocationUpdate_MakePosAndOri(&update, pos, rotY, pitch, true);
Protocol_UpdateLocation(id, &update, true);
}
@ -601,12 +601,12 @@ static void Classic_RelPositionUpdate(cc_uint8* data) {
static void Classic_OrientationUpdate(cc_uint8* data) {
struct LocationUpdate update;
EntityID id = *data++;
float rotY, headX;
float rotY, pitch;
rotY = Math_Packed2Deg(*data++);
headX = Math_Packed2Deg(*data++);
pitch = Math_Packed2Deg(*data++);
LocationUpdate_MakeOri(&update, rotY, headX);
LocationUpdate_MakeOri(&update, rotY, pitch);
Protocol_UpdateLocation(id, &update, true);
}
@ -655,7 +655,7 @@ static void Classic_ReadAbsoluteLocation(cc_uint8* data, EntityID id, cc_bool in
struct LocationUpdate update;
int x, y, z;
Vec3 pos;
float rotY, headX;
float rotY, pitch;
if (cpe_extEntityPos) {
x = (int)Stream_GetU32_BE(&data[0]);
@ -674,10 +674,10 @@ static void Classic_ReadAbsoluteLocation(cc_uint8* data, EntityID id, cc_bool in
pos.X = x/32.0f; pos.Y = y/32.0f; pos.Z = z/32.0f;
rotY = Math_Packed2Deg(*data++);
headX = Math_Packed2Deg(*data++);
pitch = Math_Packed2Deg(*data++);
if (id == ENTITIES_SELF_ID) classic_receivedFirstPos = true;
LocationUpdate_MakePosAndOri(&update, pos, rotY, headX, false);
LocationUpdate_MakePosAndOri(&update, pos, rotY, pitch, false);
Protocol_UpdateLocation(id, &update, interpolate);
}
@ -707,7 +707,7 @@ static void Classic_Reset(void) {
static void Classic_Tick(void) {
struct Entity* p = &LocalPlayer_Instance.Base;
if (!classic_receivedFirstPos) return;
Classic_WritePosition(p->Position, p->HeadY, p->HeadX);
Classic_WritePosition(p->Position, p->Yaw, p->Pitch);
}
@ -735,8 +735,8 @@ void CPE_SendPlayerClick(int button, cc_bool pressed, cc_uint8 targetId, struct
{
data[1] = button;
data[2] = !pressed;
Stream_SetU16_BE(&data[3], Ext_Deg2Packed(p->HeadY));
Stream_SetU16_BE(&data[5], Ext_Deg2Packed(p->HeadX));
Stream_SetU16_BE(&data[3], Ext_Deg2Packed(p->Yaw));
Stream_SetU16_BE(&data[5], Ext_Deg2Packed(p->Pitch));
data[7] = targetId;
Stream_SetU16_BE(&data[8], pos->BlockPos.X);
@ -1240,8 +1240,8 @@ static void CPE_SetEntityProperty(cc_uint8* data) {
update.Flags |= LOCATIONUPDATE_FLAG_ROTX;
update.RotX = LocationUpdate_Clamp((float)value); break;
case 1:
update.Flags |= LOCATIONUPDATE_FLAG_HEADY;
update.HeadY = LocationUpdate_Clamp((float)value); break;
update.Flags |= LOCATIONUPDATE_FLAG_YAW;
update.Yaw = LocationUpdate_Clamp((float)value); break;
case 2:
update.Flags |= LOCATIONUPDATE_FLAG_ROTZ;
update.RotZ = LocationUpdate_Clamp((float)value); break;
@ -1311,8 +1311,8 @@ static void CPE_SetSpawnPoint(cc_uint8* data) {
z = (cc_int16)Stream_GetU16_BE(&data[4]);
data += 6;
}
p->SpawnRotY = Math_Packed2Deg(*data++);
p->SpawnHeadX = Math_Packed2Deg(*data++);
p->SpawnYaw = Math_Packed2Deg(*data++);
p->SpawnPitch = Math_Packed2Deg(*data++);
y -= 51; /* Convert to feet position */
Vec3_Set(p->Spawn, (float)(x / 32.0f), (float)(y / 32.0f), (float)(z / 32.0f));

View File

@ -196,7 +196,7 @@ static void SPConnection_SendChat(const String* text) {
SPConnection_AddPart(&left);
}
static void SPConnection_SendPosition(Vec3 pos, float rotY, float headX) { }
static void SPConnection_SendPosition(Vec3 pos, float rotY, float pitch) { }
static void SPConnection_SendData(const cc_uint8* data, cc_uint32 len) { }
static void SPConnection_Tick(struct ScheduledTask* task) {
@ -339,8 +339,8 @@ static void MPConnection_SendChat(const String* text) {
Classic_SendChat(&left, false);
}
static void MPConnection_SendPosition(Vec3 pos, float rotY, float headX) {
Classic_WritePosition(pos, rotY, headX);
static void MPConnection_SendPosition(Vec3 pos, float rotY, float pitch) {
Classic_WritePosition(pos, rotY, pitch);
Net_SendPacket();
}

View File

@ -31,7 +31,7 @@ CC_VAR extern struct _ServerConnectionData {
/* Sends a chat message to the server. */
void (*SendChat)(const String* text);
/* Sends a position update to the server. */
void (*SendPosition)(Vec3 pos, float rotY, float headX);
void (*SendPosition)(Vec3 pos, float rotY, float pitch);
/* Sends raw data to the server. */
/* NOTE: Prefer SendBlock/Position/Chat instead, this does NOT work in singleplayer. */
void (*SendData)(const cc_uint8* data, cc_uint32 len);