Add hold model

This commit is contained in:
Derek 2021-02-28 08:39:54 +10:00
parent 2957db19e5
commit 237685dff1

View File

@ -2112,6 +2112,79 @@ static void SkinnedCubeModel_Register(void) {
}
/*########################################################################################################################*
*---------------------------------------------------------HoldModel-------------------------------------------------------*
*#########################################################################################################################*/
static void RecalcProperties(struct Entity* e) {
// Calculate block ID based on the X scale of the model
// E.g, hold|1.001 = stone (ID = 1), hold|1.041 = gold (ID = 41) etc.
BlockID block = (BlockID)((e->ModelScale.X - 0.9999f) * 1000);
if (block > 0) {
// Change the block that the player is holding
if (block < BLOCK_COUNT) e->ModelBlock = block;
else e->ModelBlock = BLOCK_AIR;
Vec3_Set(e->ModelScale, 1, 1, 1);
Entity_UpdateModelBounds(e); // Adjust size/modelAABB after changing model scale
}
}
static void DrawBlockTransform(struct Entity* e, float dispX, float dispY, float dispZ, float scale) {
static Vec3 pos;
static struct Matrix m, temp;
pos = e->Position;
pos.Y += e->Anim.BobbingModel;
Entity_GetTransform(e, pos, e->ModelScale, &m);
Matrix_Mul(&m, &m, &Gfx.View);
Matrix_Translate(&temp, dispX, dispY, dispZ);
Matrix_Mul(&m, &temp, &m);
Matrix_Scale(&temp, scale / 1.5f, scale / 1.5f, scale / 1.5f);
Matrix_Mul(&m, &temp, &m);
Model_SetupState(&block_model, e);
Gfx_LoadMatrix(MATRIX_VIEW, &m);
block_model.Draw(e);
}
static void HoldModel_Draw(struct Entity* e) {
static float handBob;
static float handIdle;
RecalcProperties(e);
handBob = (float)Math_Sin(e->Anim.WalkTime * 2.0f) * e->Anim.Swing * MATH_PI / 16.0f;
handIdle = e->Anim.RightArmX * (1.0f - e->Anim.Swing);
e->Anim.RightArmX = 0.5f + handBob + handIdle;
e->Anim.RightArmZ = 0;
Model_SetupState(Models.Human, e);
HumanModel_Draw(e);
DrawBlockTransform(e, 0.33F, (MATH_PI / 3 + handBob + handIdle) * 10 / 16 + 0.127f, -7.0f / 16, 0.5f);
}
static struct Model hold_model;
static float HoldModel_GetEyeY(struct Entity* e) {
RecalcProperties(e);
return HumanModel_GetEyeY(e);
}
static void HoldModel_Register(void) {
hold_model = human_model;
hold_model.name = "hold";
hold_model.MakeParts = Model_NoParts;
hold_model.Draw = HoldModel_Draw;
hold_model.GetEyeY = HoldModel_GetEyeY;
Model_Register(&hold_model);
}
/*########################################################################################################################*
*-------------------------------------------------------Models component--------------------------------------------------*
*#########################################################################################################################*/
@ -2146,6 +2219,7 @@ static void RegisterDefaultModels(void) {
SittingModel_Register();
CorpseModel_Register();
SkinnedCubeModel_Register();
HoldModel_Register();
}
static void OnContextLost(void* obj) {