Entity, Renderer: Add (incomplete) pig, remake entity renderer

This commit is contained in:
Er2
2023-12-03 19:35:51 +03:00
parent 0afea4428c
commit d6bf825c11
26 changed files with 283 additions and 70 deletions

View File

@@ -16,30 +16,29 @@ Cube::Cube(int a, int b)
m_posX = m_posY = m_posZ = 0.0f;
m_rotX = m_rotY = m_rotZ = 0.0f;
field_18 = false;
field_19 = true;
field_1A = false;
m_swapX = false;
m_bIgnore = false;
m_bCompiled = false;
field_2C0 = 0;
m_buffer = 0;
m_brightness = 1.0f;
field_2B4 = a;
field_2B8 = b;
m_texOffsetX = a;
m_texOffsetY = b;
}
void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
void Cube::addBox(float x, float y, float z, int displayX, int displayY, int displayZ, float scale)
{
int d = displayX, e = displayY, f = displayZ;
float x1 = x, y1 = y, z1 = z;
float x2 = x + float(d), y2 = y + float(e), z2 = z + float(f);
x1 -= g;
y1 -= g;
z1 -= g;
x2 += g;
y2 += g;
z2 += g;
x1 -= scale;
y1 -= scale;
z1 -= scale;
x2 += scale;
y2 += scale;
z2 += scale;
if (field_18)
if (m_swapX)
std::swap(x1, x2);
m_verts[0] = VertexPT(x1, y1, z1, 0.0f, 0.0f);
@@ -51,7 +50,7 @@ void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
m_verts[6] = VertexPT(x2, y2, z2, 8.0f, 8.0f);
m_verts[7] = VertexPT(x1, y2, z2, 8.0f, 0.0f);
int m = field_2B4, n = field_2B8;
int m = m_texOffsetX, n = m_texOffsetY;
m_faces[0] = PolygonQuad(&m_verts[5], &m_verts[1], &m_verts[2], &m_verts[6], m + f + d, n + f, m + f + d + f, n + f + e); // x2 face
m_faces[1] = PolygonQuad(&m_verts[0], &m_verts[4], &m_verts[7], &m_verts[3], m, n + f, m + f, n + f + e); // x1 face
@@ -68,7 +67,7 @@ void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
m_faces[3].setColor(0.5f, 0.5f, 0.5f);
#endif
if (field_18)
if (m_swapX)
{
for (int i = 0; i < 6; i++)
m_faces[i].mirror();
@@ -114,10 +113,7 @@ void Cube::drawSlow(float scale)
void Cube::render(float scale)
{
if (field_1A)
return;
if (!field_19)
if (m_bIgnore)
return;
if (!m_bCompiled)
@@ -159,10 +155,7 @@ void Cube::translateRotTo(float scale)
void Cube::translateTo(float scale)
{
if (field_1A)
return;
if (!field_19)
if (m_bIgnore)
return;
if (!hasDefaultRot())
@@ -197,6 +190,6 @@ void Cube::setPos(float x, float y, float z)
void Cube::setTexOffs(int a, int b)
{
field_2B4 = a;
field_2B8 = b;
m_texOffsetX = a;
m_texOffsetY = b;
}

View File

@@ -15,7 +15,7 @@ class Cube
public:
Cube(int, int);
void addBox(float a, float b, float c, int d, int e, int f, float g = 0);
void addBox(float x, float y, float z, int displayX, int displayY, int displayZ, float scale = 0);
// @TODO: void addTexBox(float a, float b, float c, int d, int e, int f, int g); -- No xrefs
void compile(float scale);
void draw();
@@ -39,15 +39,13 @@ public:
float m_rotX;
float m_rotY;
float m_rotZ;
bool field_18;
bool field_19;
bool field_1A;
bool m_swapX;
bool m_bIgnore;
VertexPT m_verts[8];
PolygonQuad m_faces[6];
int field_2B4;
int field_2B8;
int m_texOffsetX;
int m_texOffsetY;
bool m_bCompiled;
int field_2C0;
GLuint m_buffer;
float m_brightness;

View File

@@ -27,12 +27,12 @@ HumanoidModel::HumanoidModel(float a, float b):
m_body.setPos(0, b, 0);
m_armL.addBox(-3, -2, -2, 4, 12, 4, a);
m_armL.setPos(-5, b + 2, 0);
m_armR.field_18 = true;
m_armR.m_swapX = true;
m_armR.addBox(-1, -2, -2, 4, 12, 4, a);
m_armR.setPos(5, b + 2, 0);
m_legL.addBox(-2, 0, -2, 4, 12, 4, a);
m_legL.setPos(-2, b + 12, 0);
m_legR.field_18 = true;
m_legR.m_swapX = true;
m_legR.addBox(-2, 0, -2, 4, 12, 4, a);
m_legR.setPos(2, b + 12, 0);
}

View File

@@ -8,10 +8,11 @@
#include "Model.hpp"
Model::Model()
Model::Model(std::string texture)
{
field_4 = 0.0f;
field_8 = false;
m_texture = texture;
}
void Model::onGraphicsReset()

View File

@@ -15,7 +15,7 @@ class Mob;
class Model
{
public:
Model();
Model(std::string texture = "mob/char.png");
virtual void onGraphicsReset();
virtual void prepareMobModel(Mob*, float, float, float);
virtual void render(float, float, float, float, float, float);
@@ -25,4 +25,5 @@ public:
public:
float field_4;
bool field_8;
std::string m_texture;
};

View File

@@ -0,0 +1,107 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "PigModel.hpp"
#include "client/app/Minecraft.hpp"
PigModel::PigModel(float a, float b):
Model("mob/pig.png"),
m_head(0, 0),
m_body(28, 16),
m_armL(0, 16),
m_armR(0, 16),
m_legL(0, 16),
m_legR(0, 16),
m_snout(16, 16)
{
// @NOTE: Why 25 (19+6) is lowest Y coordinate? I have many questions to Mojang
m_head.addBox(-2, 9, -9, 8, 8, 8, a);
m_head.setPos(0, b, 0);
m_snout.addBox(0, 12, -10, 4, 3, 1);
m_snout.setPos(0, b, 0);
m_body.addBox(-3, 11, -3, 10, 8, 16, a);
m_body.setPos(0, b, 0);
m_armL.addBox(-3, 19, -2, 4, 6, 4, a);
m_armL.setPos(0, b, 0);
m_armR.addBox(3, 19, -2, 4, 6, 4, a);
m_armR.setPos(0, b, 0);
m_legL.addBox(-3, 19, 9, 4, 6, 4, a);
m_legL.setPos(0, b, 0);
m_legR.addBox(3, 19, 9, 4, 6, 4, a);
m_legR.setPos(0, b, 0);
}
void PigModel::_logGraphics()
{
Matrix m;
if (Minecraft::customDebugId == 1)
{
// @NOTE: I think most of this function was ifdef'd/commented out
m.fetchGL(GL_MODELVIEW_MATRIX);
}
}
void PigModel::onGraphicsReset()
{
m_head.m_bCompiled = false;
m_body.m_bCompiled = false;
m_armL.m_bCompiled = false;
m_armR.m_bCompiled = false;
m_legL.m_bCompiled = false;
m_legR.m_bCompiled = false;
m_snout.m_bCompiled = false;
}
void PigModel::render(float a, float b, float c, float d, float e, float f)
{
setupAnim(a, b, c, d, e, f);
m_head.render(f);
m_snout.render(f);
m_body.render(f);
m_armL.render(f);
m_armR.render(f);
m_legL.render(f);
m_legR.render(f);
_logGraphics();
}
void PigModel::setupAnim(float a2, float a3, float a4, float yaw, float pitch, float a7)
{
m_snout.m_rotY = m_head.m_rotY = std::clamp(yaw * 0.017453f, -0.5f, 0.5f);
m_snout.m_rotX = m_head.m_rotX = std::clamp(pitch * 0.017453f, -0.5f, 0.5f);
float v12 = (a2 * 0.6662f) + 3.1416f;
m_armL.m_rotX = m_legL.m_rotX = Mth::cos(a2 * 0.6662f) * 0.2f * a3;
m_armR.m_rotX = m_legR.m_rotX = Mth::cos(v12) * 0.2f * a3;
m_armL.m_rotY = m_legL.m_rotY = 0.0f;
m_armR.m_rotY = m_legR.m_rotY = 0.0f;
if (field_8)
{
float v16 = (3.1416f * -0.5f) * 0.8f;
m_armL.m_rotX = m_legL.m_rotX = v16;
m_armR.m_rotX = m_legR.m_rotX = v16;
m_armL.m_rotY = m_legL.m_rotY = (3.1416f * 0.5f) * 0.2f;
m_armR.m_rotY = m_legR.m_rotY = (3.1416f * -0.5f) * 0.2f;
}
}
void PigModel::setBrightness(float f)
{
m_head.setBrightness(f);
m_snout.setBrightness(f);
m_body.setBrightness(f);
m_armL.setBrightness(f);
m_armR.setBrightness(f);
m_legL.setBrightness(f);
m_legR.setBrightness(f);
}

View File

@@ -0,0 +1,31 @@
/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#pragma once
#include "Model.hpp"
class PigModel : public Model
{
public:
PigModel(float a, float b);
void _logGraphics();
// @TODO - No xrefs: void render(PigModel* a, float f);
void onGraphicsReset() override;
void render(float, float, float, float, float, float) override;
void setupAnim(float, float, float, float, float, float) override;
void setBrightness(float) override;
public:
Cube m_head, m_body, m_armL, m_armR, m_legL, m_legR, m_snout;
bool field_10BC;
bool field_10BD;
bool field_10BE;
};