Cleaned up Cube (#48)

* Cleaned up Cube
* Refactor/cleanup & documentation of Cube
* Renamed Tesselator to Tessellator

* Revert "Tesselator" Spelling Correction

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
This commit is contained in:
Brent
2023-08-11 03:53:50 -05:00
committed by GitHub
parent ce6c2eb553
commit b45cfc1e16
11 changed files with 129 additions and 239 deletions

View File

@@ -70,7 +70,7 @@ void Options::initDefaultValues()
m_keyBinds[15] = { "key.menu.cancel", '\b' };
#ifdef ORIGINAL_CODE
field_10 = 2;
m_rotY = 2;
field_23D = 0;
field_19 = 0;
#endif

View File

@@ -227,20 +227,20 @@ _done:
#ifdef ORIGINAL_CODE
t.begin();
t.color(0, 0);
t.vertexUV(field_20, field_C + 4.0f, 0.0f, 0.0f, 1.0f);
t.vertexUV(field_24, field_C + 4.0f, 0.0f, 1.0f, 1.0f);
t.vertexUV(field_20, m_rotX + 4.0f, 0.0f, 0.0f, 1.0f);
t.vertexUV(field_24, m_rotX + 4.0f, 0.0f, 1.0f, 1.0f);
t.color(0, 255);
t.vertexUV(field_24, field_C, 0.0f, 1.0f, 0.0f);
t.vertexUV(field_20, field_C, 0.0f, 0.0f, 0.0f);
t.vertexUV(field_24, m_rotX, 0.0f, 1.0f, 0.0f);
t.vertexUV(field_20, m_rotX, 0.0f, 0.0f, 0.0f);
t.draw();
t.begin();
t.color(0, 255);
t.vertexUV(field_20, field_10, 0.0f, 0.0f, 1.0f);
t.vertexUV(field_24, field_10, 0.0f, 1.0f, 1.0f);
t.vertexUV(field_20, m_rotY, 0.0f, 0.0f, 1.0f);
t.vertexUV(field_24, m_rotY, 0.0f, 1.0f, 1.0f);
t.color(0, 0);
t.vertexUV(field_24, field_10 - 4.0f, 0.0f, 1.0f, 0.0f);
t.vertexUV(field_20, field_10 - 4.0f, 0.0f, 0.0f, 0.0f);
t.vertexUV(field_24, m_rotY - 4.0f, 0.0f, 1.0f, 0.0f);
t.vertexUV(field_20, m_rotY - 4.0f, 0.0f, 0.0f, 0.0f);
t.draw();
#else
t.begin();

View File

@@ -9,16 +9,13 @@
#include "Cube.hpp"
#include "client/common/Utils.hpp"
float Cube::c = 180.0f / float(M_PI);
const float Cube::c = 180.0f / float(M_PI);
Cube::Cube(int a, int b)
{
m_posX = 0.0f;
m_posY = 0.0f;
m_posZ = 0.0f;
field_C = 0.0f;
field_10 = 0.0f;
field_14 = 0.0f;
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;
@@ -31,11 +28,6 @@ Cube::Cube(int a, int b)
field_2B8 = b;
}
void Cube::addBox(float a, float b, float c, int d, int e, int f)
{
addBox(a, b, c, d, e, f, 0.0f);
}
void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
{
float x1 = x, y1 = y, z1 = z;
@@ -81,7 +73,7 @@ void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
}
}
void Cube::compile(float f)
void Cube::compile(float scale)
{
xglDeleteBuffers(1, &m_buffer);
xglGenBuffers(1, &m_buffer);
@@ -90,7 +82,7 @@ void Cube::compile(float f)
t.begin();
for (int i = 0; i < 6; i++)
m_faces[i].render(t, f, m_buffer);
m_faces[i].render(t, scale);
t.end(m_buffer);
m_bCompiled = true;
@@ -101,18 +93,18 @@ void Cube::draw()
drawArrayVTC(m_buffer, 36, sizeof(Tesselator::Vertex));
}
void Cube::drawSlow(float f)
void Cube::drawSlow(float scale)
{
Tesselator& t = Tesselator::instance;
t.begin();
for (int i = 0; i < 6; i++)
m_faces[i].render(t, f, m_buffer);
m_faces[i].render(t, scale);
t.draw();
}
void Cube::render(float f)
void Cube::render(float scale)
{
if (field_1A)
return;
@@ -121,34 +113,43 @@ void Cube::render(float f)
return;
if (!m_bCompiled)
compile(f);
compile(scale);
if (field_C == 0.0f && field_10 == 0.0f && field_14 == 0.0f)
if (!hasDefaultRot())
{
if (m_posX == 0.0f && m_posY == 0 && m_posZ == 0)
{
draw();
return;
}
glPushMatrix();
glTranslatef( m_posX * f, m_posY * f, m_posZ * f);
translateRotTo(scale);
draw();
glPopMatrix();
}
else if (!hasDefaultPos())
{
translatePosTo(scale);
draw();
translatePosTo(-scale);
}
else
{
draw();
glTranslatef(-m_posX * f, -m_posY * f, -m_posZ * f);
return;
}
glPushMatrix();
glTranslatef(m_posX * f, m_posY * f, m_posZ * f);
if (field_14 != 0.0f) glRotatef(field_14 * c, 0.0f, 0.0f, 1.0f);
if (field_10 != 0.0f) glRotatef(field_10 * c, 0.0f, 1.0f, 0.0f);
if (field_C != 0.0f) glRotatef(field_C * c, 1.0f, 0.0f, 0.0f);
draw();
glPopMatrix();
}
void Cube::translateTo(float f)
void Cube::translatePosTo(float scale)
{
glTranslatef(m_posX * scale, m_posY * scale, m_posZ * scale);
}
void Cube::translateRotTo(float scale)
{
glTranslatef(m_posX * scale, m_posY * scale, m_posZ * scale);
if (m_rotZ != 0) glRotatef(m_rotZ * c, 0, 0, 1);
if (m_rotY != 0) glRotatef(m_rotY * c, 0, 1, 0);
if (m_rotX != 0) glRotatef(m_rotX * c, 1, 0, 0);
}
void Cube::translateTo(float scale)
{
if (field_1A)
return;
@@ -156,34 +157,25 @@ void Cube::translateTo(float f)
if (!field_19)
return;
if (field_C == 0.0f && field_10 == 0.0f && field_14 == 0.0f)
{
if (m_posX == 0.0f && m_posY == 0 && m_posZ == 0)
return;
glTranslatef( m_posX * f, m_posY * f, m_posZ * f);
return;
}
glTranslatef(m_posX * f, m_posY * f, m_posZ * f);
if (field_14 != 0.0f) glRotatef(field_14 * c, 0.0f, 0.0f, 1.0f);
if (field_10 != 0.0f) glRotatef(field_10 * c, 0.0f, 1.0f, 0.0f);
if (field_C != 0.0f) glRotatef(field_C * c, 1.0f, 0.0f, 0.0f);
if (!hasDefaultRot())
translateRotTo(scale);
else if (!hasDefaultPos())
translatePosTo(scale);
}
void Cube::setBrightness(float f)
void Cube::setBrightness(float b)
{
if (m_brightness != f)
if (m_brightness != b)
m_bCompiled = false;
m_brightness = f;
m_brightness = b;
m_faces[0].setColor(0.6f * f, 0.6f * f, 0.6f * f);
m_faces[1].setColor(0.6f * f, 0.6f * f, 0.6f * f);
m_faces[2].setColor(1.0f * f, 1.0f * f, 1.0f * f);
m_faces[3].setColor(0.5f * f, 0.5f * f, 0.5f * f);
m_faces[4].setColor(0.8f * f, 0.8f * f, 0.8f * f);
m_faces[5].setColor(0.8f * f, 0.8f * f, 0.8f * f);
m_faces[0].setColor(0.6f * b, 0.6f * b, 0.6f * b);
m_faces[1].setColor(0.6f * b, 0.6f * b, 0.6f * b);
m_faces[2].setColor(1.0f * b, 1.0f * b, 1.0f * b);
m_faces[3].setColor(0.5f * b, 0.5f * b, 0.5f * b);
m_faces[4].setColor(0.8f * b, 0.8f * b, 0.8f * b);
m_faces[5].setColor(0.8f * b, 0.8f * b, 0.8f * b);
}
void Cube::setPos(float x, float y, float z)

View File

@@ -15,25 +15,30 @@ class Cube
public:
Cube(int, int);
void addBox(float a, float b, float c, int d, int e, int f);
void addBox(float a, float b, float c, int d, int e, int f, float g);
void addBox(float a, float b, float c, int d, int e, int f, float g = 0);
// @TODO: void addTexBox(float a, float b, float c, int d, int e, int f, int g); -- No xrefs
void compile(float f);
void compile(float scale);
void draw();
void drawSlow(float f);
void render(float f);
void drawSlow(float scale);
void render(float scale);
void setPos(float x, float y, float z);
void setTexOffs(int a, int b);
void translateTo(float f);
void setBrightness(float f);
void translateTo(float scale);
void setBrightness(float brightness);
private:
bool hasDefaultPos() { return m_posX == 0 && m_posY == 0 && m_posZ == 0; }
bool hasDefaultRot() { return m_rotX == 0 && m_rotY == 0 && m_rotZ == 0; }
void translatePosTo(float scale);
void translateRotTo(float scale);
public:
float m_posX;
float m_posY;
float m_posZ;
float field_C;
float field_10;
float field_14;
float m_rotX;
float m_rotY;
float m_rotZ;
bool field_18;
bool field_19;
bool field_1A;
@@ -46,6 +51,6 @@ public:
GLuint m_buffer;
float m_brightness;
static float c;
static const float c;
};

View File

@@ -73,63 +73,63 @@ void HumanoidModel::render(float a, float b, float c, float d, float e, float f)
void HumanoidModel::setupAnim(float a2, float a3, float a4, float a5, float a6, float a7)
{
//a6 = pitch, a5 = yaw-ish
m_head.field_10 = a5 * 0.017453f;
m_head.field_C = a6 * 0.017453f;
if (m_head.field_C < -1.0f)
m_head.field_C = -1.0f;
if (m_head.field_C > 1.0f)
m_head.field_C = 1.0f;
m_head.m_rotY = a5 * 0.017453f;
m_head.m_rotX = a6 * 0.017453f;
if (m_head.m_rotX < -1.0f)
m_head.m_rotX = -1.0f;
if (m_head.m_rotX > 1.0f)
m_head.m_rotX = 1.0f;
float v12 = (a2 * 0.6662f) + 3.1416f;
m_armL.field_C = (Mth::cos(v12) * 2.0f * a3) * 0.5f;
m_armR.field_C = Mth::cos(a2 * 0.6662f) * 2.0f * a3 * 0.5f; // @HUH: multiplying by 2 and also by 1/2
m_armL.field_14 = 0.0f;
m_armR.field_14 = 0.0f;
m_legL.field_C = (Mth::cos(a2 * 0.6662f) * 1.4f) * a3;
m_legR.field_C = (Mth::cos(v12) * 1.4f) * a3;
m_legL.field_10 = 0.0f;
m_legR.field_10 = 0.0f;
m_armL.m_rotX = (Mth::cos(v12) * 2.0f * a3) * 0.5f;
m_armR.m_rotX = Mth::cos(a2 * 0.6662f) * 2.0f * a3 * 0.5f; // @HUH: multiplying by 2 and also by 1/2
m_armL.m_rotZ = 0.0f;
m_armR.m_rotZ = 0.0f;
m_legL.m_rotX = (Mth::cos(a2 * 0.6662f) * 1.4f) * a3;
m_legR.m_rotX = (Mth::cos(v12) * 1.4f) * a3;
m_legL.m_rotY = 0.0f;
m_legR.m_rotY = 0.0f;
if (field_8)
{
float v15 = (3.1416f * -0.5f) * 0.4f;
m_armL.field_C += v15;
m_armR.field_C += v15;
m_armL.m_rotX += v15;
m_armR.m_rotX += v15;
float v16 = (3.1416f * -0.5f) * 0.8f;
m_legL.field_C = v16;
m_legR.field_C = v16;
m_legL.field_10 = (3.1416f * 0.5f) * 0.2f;
m_legR.field_10 = (3.1416f * -0.5f) * 0.2f;
m_legL.m_rotX = v16;
m_legR.m_rotX = v16;
m_legL.m_rotY = (3.1416f * 0.5f) * 0.2f;
m_legR.m_rotY = (3.1416f * -0.5f) * 0.2f;
}
if (field_10BC)
m_armR.field_C = ((3.1416f * 0.5f) * -0.2f) + (m_armR.field_C * 0.5f);
m_armR.m_rotX = ((3.1416f * 0.5f) * -0.2f) + (m_armR.m_rotX * 0.5f);
if (field_10BD)
m_armL.field_C = ((3.1416f * 0.5f) * -0.2f) + (m_armL.field_C * 0.5f);
m_armL.m_rotX = ((3.1416f * 0.5f) * -0.2f) + (m_armL.m_rotX * 0.5f);
m_armL.field_10 = 0.0f;
m_armR.field_10 = 0.0f;
m_armL.m_rotY = 0.0f;
m_armR.m_rotY = 0.0f;
if (field_4 > -9990.0f)
{
m_body.field_10 = Mth::sin(Mth::sqrt(field_4) * 3.1416f * 2.0f) * 0.2f;
m_armL.m_posZ = 5.0f * Mth::sin(m_body.field_10);
m_armL.m_posX = -5.0f * Mth::cos(m_body.field_10);
m_armR.m_posZ = -5.0f * Mth::sin(m_body.field_10);
m_armR.m_posX = 5.0f * Mth::cos(m_body.field_10);
m_armL.field_10 = m_armL.field_10 + m_body.field_10;
m_armR.field_10 = m_armR.field_10 + m_body.field_10;
m_body.m_rotY = Mth::sin(Mth::sqrt(field_4) * 3.1416f * 2.0f) * 0.2f;
m_armL.m_posZ = 5.0f * Mth::sin(m_body.m_rotY);
m_armL.m_posX = -5.0f * Mth::cos(m_body.m_rotY);
m_armR.m_posZ = -5.0f * Mth::sin(m_body.m_rotY);
m_armR.m_posX = 5.0f * Mth::cos(m_body.m_rotY);
m_armL.m_rotY = m_armL.m_rotY + m_body.m_rotY;
m_armR.m_rotY = m_armR.m_rotY + m_body.m_rotY;
float o = 1.0f - field_4;
m_armR.field_C += m_body.field_10;
m_armL.field_C -= -((m_head.field_C - 0.7f) * Mth::sin(3.1416f * field_4)) * 0.75f + Mth::sin((1.0f - o * o * o * o) * 3.1416f) * 1.2f;
m_armL.field_10 += m_body.field_10 * 2.0f;
m_armL.field_14 = Mth::sin(field_4 * 3.1416f) * -0.4f;
m_armR.m_rotX += m_body.m_rotY;
m_armL.m_rotX -= -((m_head.m_rotX - 0.7f) * Mth::sin(3.1416f * field_4)) * 0.75f + Mth::sin((1.0f - o * o * o * o) * 3.1416f) * 1.2f;
m_armL.m_rotY += m_body.m_rotY * 2.0f;
m_armL.m_rotZ = Mth::sin(field_4 * 3.1416f) * -0.4f;
}
if (field_10BE) // sneaking?
{
m_body.field_C = 0.5f;
m_armL.field_C += 0.4f;
m_armR.field_C += 0.4f;
m_body.m_rotX = 0.5f;
m_armL.m_rotX += 0.4f;
m_armR.m_rotX += 0.4f;
m_legL.m_posZ = 4.0f;
m_legR.m_posZ = 4.0f;
m_legL.m_posY = 9.0f;
@@ -138,7 +138,7 @@ void HumanoidModel::setupAnim(float a2, float a3, float a4, float a5, float a6,
}
else
{
m_body.field_C = 0.0f;
m_body.m_rotX = 0.0f;
m_legL.m_posZ = 0.0f;
m_head.m_posY = 0.0f;
m_legR.m_posZ = 0.0f;
@@ -146,10 +146,10 @@ void HumanoidModel::setupAnim(float a2, float a3, float a4, float a5, float a6,
m_legR.m_posY = 12.0f;
}
m_armL.field_14 += Mth::cos(a4 * 0.09f) * 0.05f + 0.05f;
m_armR.field_14 -= Mth::cos(a4 * 0.09f) * 0.05f + 0.05f;
m_armL.field_C += Mth::sin(a4 * 0.067f) * 0.05f;
m_armR.field_C += Mth::sin(a4 * 0.067f) * -0.05f;
m_armL.m_rotZ += Mth::cos(a4 * 0.09f) * 0.05f + 0.05f;
m_armR.m_rotZ -= Mth::cos(a4 * 0.09f) * 0.05f + 0.05f;
m_armL.m_rotX += Mth::sin(a4 * 0.067f) * 0.05f;
m_armR.m_rotX += Mth::sin(a4 * 0.067f) * -0.05f;
}
void HumanoidModel::setBrightness(float f)
@@ -161,110 +161,3 @@ void HumanoidModel::setBrightness(float f)
m_body.setBrightness(f);
m_head.setBrightness(f);
}
/* Keeping the original around just in case:
void HumanoidModel::setupAnim(float a2, float a3, float a4, float a5, float a6, float a7)
{
this->m_head.field_10 = a5 * 0.017453f;
float v11 = a6 * 0.017453f;
if ((a6 * 0.017453f) <= 1.0f)
{
if (v11 < -1.0f)
v11 = -1.0f;
}
else
{
v11 = 1.0f;
}
this->m_head.field_C = v11;
float v12 = (a2 * 0.6662f) + 3.1416f;
float v13 = Mth::cos(v12);
this->m_armL.field_C = ((v13 + v13) * a3) * 0.5f;
float v14 = Mth::cos(a2 * 0.6662f);
this->m_armR.field_C = ((v14 + v14) * a3) * 0.5f;
this->m_armL.field_14 = 0.0f;
this->m_armR.field_14 = 0.0f;
this->m_legL.field_C = (Mth::cos(a2 * 0.6662f) * 1.4f) * a3;
this->m_legR.field_C = (Mth::cos(v12) * 1.4f) * a3;
this->m_legL.field_10 = 0.0f;
this->m_legR.field_10 = 0.0f;
if (this->field_8)
{
float v15 = (3.1416f * -0.5f) * 0.4f;
this->m_armL.field_C = this->m_armL.field_C + v15;
this->m_armR.field_C = this->m_armR.field_C + v15;
float v16 = (3.1416f * -0.5f) * 0.8f;
this->m_legL.field_C = v16;
this->m_legR.field_C = v16;
this->m_legL.field_10 = (3.1416f * 0.5f) * 0.2f;
this->m_legR.field_10 = (3.1416f * -0.5f) * 0.2f;
}
if (this->field_10BC)
this->m_armR.field_C = ((3.1416f * 0.5f) * -0.2f) + (this->m_armR.field_C * 0.5f);
if (this->field_10BD)
this->m_armL.field_C = ((3.1416f * 0.5f) * -0.2f) + (this->m_armL.field_C * 0.5f);
this->m_armL.field_10 = 0.0f;
this->m_armR.field_10 = 0.0f;
if (field_4 > -9990.0f)
{
float v22 = Mth::sqrt(field_4);
float v23 = Mth::sin((v22 * 3.1416f) + (v22 * 3.1416f));
this->m_body.field_10 = v23 * 0.2f;
float v24 = Mth::sin(v23 * 0.2f) * 5.0f;
float bf10_1 = this->m_body.field_10;
this->m_armL.m_posZ = v24;
float v26 = Mth::cos(bf10_1) * -5.0f;
float bf10_2 = this->m_body.field_10;
this->m_armL.m_posX = v26;
float v28 = Mth::sin(bf10_2) * -5.0f;
float bf10_3 = this->m_body.field_10;
this->m_armR.m_posZ = v28;
this->m_armR.m_posX = Mth::cos(bf10_3) * 5.0f;
float bf10_4 = this->m_body.field_10;
this->m_armL.field_10 = this->m_armL.field_10 + bf10_4;
this->m_armR.field_10 = this->m_armR.field_10 + bf10_4;
float v31 = this->m_armR.field_C + bf10_4;
float v32 = 1.0f - this->field_4;
this->m_armR.field_C = v31;
float v33 = Mth::sin((1.0f - ((v32 * v32) * (v32 * v32))) * 3.1416f);
float v34 = Mth::sin(3.1416f * this->field_4);
float bf10_times_2 = this->m_body.field_10 + this->m_body.field_10;
this->m_armL.field_C = this->m_armL.field_C - ((-((this->m_head.field_C - 0.7f) * v34) * 0.75f) + (v33 * 1.2f));
float v36 = this->m_armL.field_10 + bf10_times_2;
float v37 = this->field_4 * 3.1416f;
this->m_armL.field_10 = v36;
this->m_armL.field_14 = Mth::sin(v37) * -0.4f;
}
if (this->field_10BE)
{
m_body.field_C = 0.5f;
m_armL.field_C += 0.4f;
m_armR.field_C += 0.4f;
m_legL.m_posZ = 4.0f;
m_legR.m_posZ = 4.0f;
m_legL.m_posY = 9.0f;
m_legR.m_posY = 9.0f;
m_head.m_posY = 1.0f;
}
else
{
m_body.field_C = 0.0f;
m_legL.m_posZ = 0.0f;
m_head.m_posY = 0.0f;
m_legR.m_posZ = 0.0f;
m_legL.m_posY = 12.0f;
m_legR.m_posY = 12.0f;
}
float v18 = this->m_armL.field_14;
this->m_armL.field_14 = v18 + ((Mth::cos(a4 * 0.09f) * 0.05f) + 0.05f);
float v19 = this->m_armR.field_14;
this->m_armR.field_14 = v19 - ((Mth::cos(a4 * 0.09f) * 0.05f) + 0.05f);
float v20 = this->m_armL.field_C;
this->m_armL.field_C = v20 + (Mth::sin(a4 * 0.067f) * 0.05f);
float v21 = this->m_armR.field_C;
this->m_armR.field_C = v21 + (Mth::sin(a4 * 0.067f) * -0.05f);
}
*/

View File

@@ -68,7 +68,7 @@ void PolygonQuad::mirror()
std::swap(m_verts[1], m_verts[2]);
}
void PolygonQuad::render(Tesselator& t, float scale, int unused)
void PolygonQuad::render(Tesselator& t, float scale)
{
for (int i = 0; i < 4; i++)
{

View File

@@ -25,7 +25,7 @@ public:
void flipNormal();
void mirror();
void render(Tesselator& t, float scale, int unused);
void render(Tesselator& t, float scale);
#ifdef ENH_ENTITY_SHADING
void setColor(float r, float g, float b);

View File

@@ -532,7 +532,7 @@ void GameRenderer::render(float f)
float yd = 4.0f * mult1 * pMC->field_D24;
float old_field_84 = field_84;
field_84 = float(field_C) + f;
field_84 = float(m_rotX) + f;
float diff_field_84 = field_84 - old_field_84;
field_74 += xd;
field_78 += yd;
@@ -546,10 +546,10 @@ void GameRenderer::render(float f)
if (!pMC->m_options.field_240)
{
// @TODO: untangle this code
float v17 = xd + field_14;
float v17 = xd + m_rotZ;
float v18 = field_18;
float v19 = field_1C;
field_14 = v17;
m_rotZ = v17;
float v20 = mult1 * 0.25f * (v17 - v18);
float v21 = v19 + (v20 - v19) * 0.5f;
field_1C = v21;

View File

@@ -30,8 +30,8 @@ void TripodCameraRenderer::render(Entity* entity, float x, float y, float z, flo
{
glPushMatrix();
glTranslatef(x, y, z);
m_cube.field_C = 0.017453f * (180.0f + 0.5f * entity->m_pitch);
m_cube.field_10 = -0.017453f * entity->m_yaw;
m_cube.m_rotX = 0.017453f * (180.0f + 0.5f * entity->m_pitch);
m_cube.m_rotY = -0.017453f * entity->m_yaw;
Tesselator& t = Tesselator::instance;
t.color(1.0f, 1.0f, 1.0f);