Implement missing methods in IModel

This commit is contained in:
UnknownShadow200 2017-09-04 09:32:35 +10:00
parent ba34b5e8ac
commit 20d7ea6dfc
8 changed files with 82 additions and 31 deletions

View File

@ -104,7 +104,6 @@ namespace ClassicalSharp.Model {
CuboidDrawer drawer = new CuboidDrawer(); CuboidDrawer drawer = new CuboidDrawer();
void DrawParts(bool sprite) { void DrawParts(bool sprite) {
// SwitchOrder is needed for held block, which renders without depth testing
if (sprite) { if (sprite) {
SpriteXQuad(Side.Right, false); SpriteXQuad(Side.Right, false);
SpriteZQuad(Side.Back, false); SpriteZQuad(Side.Back, false);

View File

@ -37,7 +37,7 @@ namespace ClassicalSharp.Mode {
if (game.Inventory.Selected == Block.RedMushroom) { if (game.Inventory.Selected == Block.RedMushroom) {
DepleteInventoryHeld(); DepleteInventoryHeld();
game.LocalPlayer.Health -= 5; game.LocalPlayer.Health -= 5;
CheckPlayerDied(); CheckPlayerDied();
return true; return true;
} else if (game.Inventory.Selected == Block.BrownMushroom) { } else if (game.Inventory.Selected == Block.BrownMushroom) {
DepleteInventoryHeld(); DepleteInventoryHeld();

View File

@ -94,7 +94,9 @@ void PerspectiveCamera_UpdateMouseRotation(void) {
if (update->HeadX >= 90.0f && update->HeadX <= 270.0f) { if (update->HeadX >= 90.0f && update->HeadX <= 270.0f) {
update->HeadX = player->Interp.Next.HeadX < 180.0f ? 89.9f : 270.1f; update->HeadX = player->Interp.Next.HeadX < 180.0f ? 89.9f : 270.1f;
} }
game.LocalPlayer.SetLocation(update, false);
Entity* e = &player->Base.Base;
e->SetLocation(e, update, false);
} }
void PerspectiveCamera_UpdateMouse(void) { void PerspectiveCamera_UpdateMouse(void) {

View File

@ -50,7 +50,8 @@ Vector3 Entity_GetEyePosition(Entity* entity) {
return pos; return pos;
} }
void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale, Matrix* m) { void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale) {
Matrix* m = &entity->Transform;
*m = Matrix_Identity; *m = Matrix_Identity;
Matrix tmp; Matrix tmp;
@ -463,17 +464,17 @@ void NetInterpComp_AddState(NetInterpComp* interp, InterpState state) {
interp->States[interp->StatesCount] = state; interp->StatesCount++; interp->States[interp->StatesCount] = state; interp->StatesCount++;
} }
void NetInterpComp_SetLocation(NetInterpComp* interp, LocationUpdate update, bool interpolate) { void NetInterpComp_SetLocation(NetInterpComp* interp, LocationUpdate* update, bool interpolate) {
InterpState last = interp->Cur; InterpState last = interp->Cur;
InterpState* cur = &interp->Cur; InterpState* cur = &interp->Cur;
if (update.IncludesPosition) { if (update->IncludesPosition) {
InterpComp_SetPos(cur, &update); InterpComp_SetPos(cur, update);
} }
cur->RotX = NetInterpComp_Next(update.RotX, cur->RotX); cur->RotX = NetInterpComp_Next(update->RotX, cur->RotX);
cur->RotZ = NetInterpComp_Next(update.RotZ, cur->RotZ); cur->RotZ = NetInterpComp_Next(update->RotZ, cur->RotZ);
cur->HeadX = NetInterpComp_Next(update.HeadX, cur->HeadX); cur->HeadX = NetInterpComp_Next(update->HeadX, cur->HeadX);
cur->HeadY = NetInterpComp_Next(update.RotY, cur->HeadY); cur->HeadY = NetInterpComp_Next(update->RotY, cur->HeadY);
if (!interpolate) { if (!interpolate) {
interp->Base.Prev = *cur; interp->Base.PrevRotY = cur->HeadY; interp->Base.Prev = *cur; interp->Base.PrevRotY = cur->HeadY;
@ -512,13 +513,13 @@ Real32 LocalInterpComp_Next(Real32 next, Real32 cur, Real32* last, bool interpol
return next; return next;
} }
void LocalInterpComp_SetLocation(InterpComp* interp, LocationUpdate update, bool interpolate) { void LocalInterpComp_SetLocation(InterpComp* interp, LocationUpdate* update, bool interpolate) {
Entity* entity = &LocalPlayer_Instance.Base.Base; Entity* entity = &LocalPlayer_Instance.Base.Base;
InterpState* prev = &interp->Prev; InterpState* prev = &interp->Prev;
InterpState* next = &interp->Next; InterpState* next = &interp->Next;
if (update.IncludesPosition) { if (update->IncludesPosition) {
InterpComp_SetPos(next, &update); InterpComp_SetPos(next, update);
Real32 blockOffset = next->Pos.Y - Math_Floor(next->Pos.Y); Real32 blockOffset = next->Pos.Y - Math_Floor(next->Pos.Y);
if (blockOffset < Entity_Adjustment) { if (blockOffset < Entity_Adjustment) {
next->Pos.Y += Entity_Adjustment; next->Pos.Y += Entity_Adjustment;
@ -529,15 +530,15 @@ void LocalInterpComp_SetLocation(InterpComp* interp, LocationUpdate update, bool
} }
} }
next->RotX = LocalInterpComp_Next(update.RotX, next->RotX, &prev->RotX, interpolate); next->RotX = LocalInterpComp_Next(update->RotX, next->RotX, &prev->RotX, interpolate);
next->RotZ = LocalInterpComp_Next(update.RotZ, next->RotZ, &prev->RotZ, interpolate); next->RotZ = LocalInterpComp_Next(update->RotZ, next->RotZ, &prev->RotZ, interpolate);
next->HeadX = LocalInterpComp_Next(update.HeadX, next->HeadX, &prev->HeadX, interpolate); next->HeadX = LocalInterpComp_Next(update->HeadX, next->HeadX, &prev->HeadX, interpolate);
next->HeadY = LocalInterpComp_Next(update.RotY, next->HeadY, &prev->HeadY, interpolate); next->HeadY = LocalInterpComp_Next(update->RotY, next->HeadY, &prev->HeadY, interpolate);
if (update.RotY != LocationUpdate_Excluded) { if (update->RotY != LocationUpdate_Excluded) {
if (!interpolate) { if (!interpolate) {
interp->NextRotY = update.RotY; interp->NextRotY = update->RotY;
entity->RotY = update.RotY; entity->RotY = update->RotY;
interp->RotYCount = 0; interp->RotYCount = 0;
} else { } else {
/* Body Y rotation lags slightly behind */ /* Body Y rotation lags slightly behind */

View File

@ -98,6 +98,17 @@ typedef struct Entity_ {
Vector3 ModelScale; Vector3 ModelScale;
/* Returns the size of the model that is used for collision detection. */ /* Returns the size of the model that is used for collision detection. */
Vector3 Size; Vector3 Size;
/* Transformation matrix of this entity when rendering */
Matrix Transform;
/* Whether no shading should be applied to the faces of model parts of this entity's model. */
bool NoShade;
/* TODO: SHOULD THESE BE A SEPARATE VTABLE STRUCT? (only need 1 shared pointer that way) */
/* Sets the location of this entity. */
void (*SetLocation)(struct Entity_* entity, LocationUpdate* update, bool interpolate);
/* Gets the colour of this entity for rendering. */
PackedCol (*GetCol)(struct Entity_* entity);
} Entity; } Entity;
@ -108,7 +119,7 @@ void Entity_Init(Entity* entity);
Vector3 Entity_GetEyePosition(Entity* entity); Vector3 Entity_GetEyePosition(Entity* entity);
/* Calculates the transformation matrix for the given entity. */ /* Calculates the transformation matrix for the given entity. */
void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale, Matrix* m); void Entity_GetTransform(Entity* entity, Vector3 pos, Vector3 scale);
/* Returns the bounding box that contains the model, without any rotations applied. */ /* Returns the bounding box that contains the model, without any rotations applied. */
void Entity_GetPickingBounds(Entity* entity, AABB* bb); void Entity_GetPickingBounds(Entity* entity, AABB* bb);
@ -236,7 +247,7 @@ typedef struct InterpComp_ {
void InterpComp_LerpAngles(InterpComp* interp, Entity* entity, Real32 t); void InterpComp_LerpAngles(InterpComp* interp, Entity* entity, Real32 t);
void LocalInterpComp_SetLocation(InterpComp* interp, LocationUpdate update, bool interpolate); void LocalInterpComp_SetLocation(InterpComp* interp, LocationUpdate* update, bool interpolate);
void LocalInterpComp_AdvanceState(InterpComp* interp); void LocalInterpComp_AdvanceState(InterpComp* interp);
@ -249,7 +260,7 @@ typedef struct NetInterpComp_ {
InterpState States[10]; InterpState States[10];
} NetInterpComp; } NetInterpComp;
void NetInterpComp_SetLocation(NetInterpComp* interp, LocationUpdate update, bool interpolate); void NetInterpComp_SetLocation(NetInterpComp* interp, LocationUpdate* update, bool interpolate);
void NetInterpComp_AdvanceState(NetInterpComp* interp); void NetInterpComp_AdvanceState(NetInterpComp* interp);
#endif #endif

View File

@ -5,6 +5,7 @@
#include "ModelCache.h" #include "ModelCache.h"
#include "GraphicsCommon.h" #include "GraphicsCommon.h"
#include "FrustumCulling.h" #include "FrustumCulling.h"
#include "GraphicsAPI.h"
#define UV_POS_MASK ((UInt16)0x7FFF) #define UV_POS_MASK ((UInt16)0x7FFF)
#define UV_MAX ((UInt16)0x8000) #define UV_MAX ((UInt16)0x8000)
@ -20,8 +21,8 @@ void ModelPart_Init(ModelPart* part, Int32 offset, Int32 count, Real32 rotX, Rea
part->RotX = rotX; part->RotY = rotY; part->RotZ = rotZ; part->RotX = rotX; part->RotY = rotY; part->RotZ = rotZ;
} }
void IModel_GetTransform(Matrix* m, Entity* entity, Vector3 pos) { void IModel_GetTransform(Entity* entity, Vector3 pos) {
Entity_GetTransform(entity, pos, entity->ModelScale, m); Entity_GetTransform(entity, pos, entity->ModelScale);
} }
void IModel_Init(IModel* model) { void IModel_Init(IModel* model) {
@ -76,6 +77,43 @@ Real32 IModel_RenderDistance(Entity* entity) {
return dx * dx + dy * dy + dz * dz; return dx * dx + dy * dy + dz * dz;
} }
Matrix IModel_transform;
void IModel_Render(IModel* model, Entity* entity) {
Vector3 pos = entity->Position;
if (model->Bobbing) pos.Y += entity->Anim.BobbingModel;
IModel_SetupState(model, entity);
Gfx_SetBatchFormat(VertexFormat_P3fT2fC4b);
Gfx_PushMatrix();
model->GetTransform(entity, pos);
Gfx_MultiplyMatrix(&entity->Transform);
model->DrawModel(entity);
Gfx_PopMatrix();
}
void IModel_SetupState(IModel* model, Entity* entity) {
model->index = 0;
PackedCol col = entity->GetCol(entity);
IModel_uScale = 1.0f / 64.0f;
IModel_vScale = 1.0f / 32.0f;
IModel_Cols[0] = col;
if (!entity->NoShade) {
IModel_Cols[1] = PackedCol_Scale(col, PackedCol_ShadeYBottom);
IModel_Cols[2] = PackedCol_Scale(col, PackedCol_ShadeZ);
IModel_Cols[4] = PackedCol_Scale(col, PackedCol_ShadeX);
} else {
IModel_Cols[1] = col; IModel_Cols[2] = col; IModel_Cols[4] = col;
}
IModel_Cols[3] = IModel_Cols[2];
IModel_Cols[5] = IModel_Cols[4];
Real32 yawDelta = entity->HeadY - entity->RotY;
IModel_cosHead = Math_Cos(yawDelta * MATH_DEG2RAD);
IModel_sinHead = Math_Sin(yawDelta * MATH_DEG2RAD);
}
void IModel_UpdateVB(void) { void IModel_UpdateVB(void) {
IModel* model = IModel_ActiveModel; IModel* model = IModel_ActiveModel;
GfxCommon_UpdateDynamicVb_IndexedTris(ModelCache_Vb, ModelCache_Vertices, model->index); GfxCommon_UpdateDynamicVb_IndexedTris(ModelCache_Vb, ModelCache_Vertices, model->index);

View File

@ -88,7 +88,7 @@ typedef struct IModel_ {
/* Performs the actual rendering of an entity model. */ /* Performs the actual rendering of an entity model. */
void (*DrawModel)(Entity* entity); void (*DrawModel)(Entity* entity);
/* Gets the transformation matrix of this entity. */ /* Gets the transformation matrix of this entity. */
void (*GetTransform)(Matrix* m, Entity* entity, Vector3 pos); void (*GetTransform)(Entity* entity, Vector3 pos);
/* The maximum scale the entity can have (for collisions and rendering).*/ /* The maximum scale the entity can have (for collisions and rendering).*/
Real32 MaxScale; Real32 MaxScale;

View File

@ -958,9 +958,9 @@ void SittingModel_GetPickingBounds(AABB* bb) {
8.0f / 16.0f, (32.0f - SIT_OFFSET) / 16.0f, 4.0f / 16.0f); 8.0f / 16.0f, (32.0f - SIT_OFFSET) / 16.0f, 4.0f / 16.0f);
} }
void SittingModel_GetTransform(Matrix* m, Entity* entity, Vector3 pos) { void SittingModel_GetTransform(Entity* entity, Vector3 pos) {
pos.Y -= (SIT_OFFSET / 16.0f) * entity->ModelScale.Y; pos.Y -= (SIT_OFFSET / 16.0f) * entity->ModelScale.Y;
Entity_GetTransform(entity, pos, entity->ModelScale, m); Entity_GetTransform(entity, pos, entity->ModelScale);
} }
void SittingModel_DrawModel(Entity* entity) { void SittingModel_DrawModel(Entity* entity) {
@ -996,9 +996,9 @@ void HeadModel_GetPickingBounds(AABB* bb) {
4.0f / 16.0f, 8.0f / 16.0f, 4.0f / 16.0f); 4.0f / 16.0f, 8.0f / 16.0f, 4.0f / 16.0f);
} }
void HeadModel_GetTransform(Matrix* m, Entity* entity, Vector3 pos) { void HeadModel_GetTransform(Entity* entity, Vector3 pos) {
pos.Y -= (24.0f / 16.0f) * entity->ModelScale.Y; pos.Y -= (24.0f / 16.0f) * entity->ModelScale.Y;
Entity_GetTransform(entity, pos, entity->ModelScale, m); Entity_GetTransform(entity, pos, entity->ModelScale);
} }
void HeadModel_DrawModel(Entity* entity) { void HeadModel_DrawModel(Entity* entity) {