Files
mcpe/source/client/model/Cube.cpp
Brent f12a3c1c61 Visual Studio Project Overhaul + Cleanup (#80)
* Visual Studio Project Overhaul + Cleanup
* SDL2 project for Windows
* Re-added game client icon to SDL2 code
* Renamed "AppPlatform_windows" to "AppPlatform_win32" (this is the name of the Windows API and is not representative of the architecture type)
* Renamed "LoggerWindows" to "LoggerWin32"
* Renamed "SoundSystemWindows to "SoundSystemDS" (DirectSound). This may be used for the 360, so it wouldn't really be Windows-specific then.
* Moved "ClientSideNetworkHandler" from "network" to "client/network". We don't need it being compiled for the server if the client's the only thing that needs it.
* I wonder if this still works on macOS...

* Bugfixes & Fixed for macOS

* Options::savePropertiesToFile Logging Bugfix

* Silence Winsock Deprecation Warnings in RakNet

* VS Project Improvements
- Replaced 50 billion relative paths with $(MC_ROOT)
- Added $(RAKNET_PATH) variable to override RakNet location
- Re-added gitignore for .vcxproj.user files
- Added debugging config to Directory.Builds.props
- Slimmed down project configurations for SDL2

* VS Project Config Bugfixes
- Fixed RakNet header path for additional includes

* RakNet Target for XCode

* XCode Project Config Fixes

* Packet logging

* Network VS Project Filter Fix

* Fix RakNet Packet ID Length
We previously didn't have consistency between old and new C++ regarding PacketType enum length. Now we do. This is required or else it completely breaks networking between the versions.

* Additional RakNet Error Handling

* Disable packet logging

* * Fix CMakeLists.txt

This reflects the relocation of ClientSideNetworkHandler.cpp.

* * Also add renderer/GL/GL.cpp to the CMakeLists.txt

* * Replace libpng with stb_image

* * Fix buggy water behavior.

* * Put the CMakeLists of the SDL project in debug mode

* Visual Studio 2010 Support

* * Change the SdlIoCallbacks from an array to a single member.

This fixes compilation of the sdl2 target on VS.

* * Fix missing _error label.

* Revert "* Fix missing _error label."

This reverts commit 99a057fc84049a16c864bd840fb439a008af5c74.

* Revert "* Replace libpng with stb_image"

* info_updateGame Tiles

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
2023-10-22 10:08:59 +03:00

203 lines
4.6 KiB
C++

/********************************************************************
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 "Cube.hpp"
#include "renderer/GL/GL.hpp"
const float Cube::c = 180.0f / float(M_PI);
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_bCompiled = false;
field_2C0 = 0;
m_buffer = 0;
m_brightness = 1.0f;
field_2B4 = a;
field_2B8 = b;
}
void Cube::addBox(float x, float y, float z, int d, int e, int f, float g)
{
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;
if (field_18)
std::swap(x1, x2);
m_verts[0] = VertexPT(x1, y1, z1, 0.0f, 0.0f);
m_verts[1] = VertexPT(x2, y1, z1, 0.0f, 8.0f);
m_verts[2] = VertexPT(x2, y2, z1, 8.0f, 8.0f);
m_verts[3] = VertexPT(x1, y2, z1, 8.0f, 0.0f);
m_verts[4] = VertexPT(x1, y1, z2, 0.0f, 0.0f);
m_verts[5] = VertexPT(x2, y1, z2, 0.0f, 8.0f);
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;
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
m_faces[2] = PolygonQuad(&m_verts[5], &m_verts[4], &m_verts[0], &m_verts[1], m + f, n, m + f + d, n + f); // up face
m_faces[3] = PolygonQuad(&m_verts[2], &m_verts[3], &m_verts[7], &m_verts[6], m + f + d, n, m + f + d + d, n + f); // down face
m_faces[4] = PolygonQuad(&m_verts[1], &m_verts[0], &m_verts[3], &m_verts[2], m + f, n + f, m + f + d, n + f + e); // z1 face
m_faces[5] = PolygonQuad(&m_verts[4], &m_verts[5], &m_verts[6], &m_verts[7], m + f + d + f, n + f, m + f + d + f + d, n + f + e); // z2 face
#ifdef ENH_ENTITY_SHADING
m_faces[0].setColor(0.6f, 0.6f, 0.6f);
m_faces[1].setColor(0.6f, 0.6f, 0.6f);
m_faces[4].setColor(0.8f, 0.8f, 0.8f);
m_faces[5].setColor(0.8f, 0.8f, 0.8f);
m_faces[3].setColor(0.5f, 0.5f, 0.5f);
#endif
if (field_18)
{
for (int i = 0; i < 6; i++)
m_faces[i].mirror();
}
}
void Cube::compile(float scale)
{
if (m_bCompiled)
xglDeleteBuffers(1, &m_buffer);
xglGenBuffers(1, &m_buffer);
Tesselator& t = Tesselator::instance;
t.begin();
for (int i = 0; i < 6; i++)
m_faces[i].render(t, scale);
t.end(m_buffer);
m_bCompiled = true;
}
void Cube::draw()
{
#ifdef ENH_ENTITY_SHADING
drawArrayVTC(m_buffer, 36, sizeof(Tesselator::Vertex));
#else
drawArrayVT(m_buffer, 36, sizeof(Tesselator::Vertex));
#endif
}
void Cube::drawSlow(float scale)
{
Tesselator& t = Tesselator::instance;
t.begin();
for (int i = 0; i < 6; i++)
m_faces[i].render(t, scale);
t.draw();
}
void Cube::render(float scale)
{
if (field_1A)
return;
if (!field_19)
return;
if (!m_bCompiled)
compile(scale);
if (!hasDefaultRot())
{
glPushMatrix();
translateRotTo(scale);
draw();
glPopMatrix();
}
else if (!hasDefaultPos())
{
translatePosTo(scale);
draw();
translatePosTo(-scale);
}
else
{
draw();
}
}
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;
if (!field_19)
return;
if (!hasDefaultRot())
translateRotTo(scale);
else if (!hasDefaultPos())
translatePosTo(scale);
}
void Cube::setBrightness(float b)
{
if (m_brightness != b)
m_bCompiled = false;
m_brightness = b;
#ifdef ENH_ENTITY_SHADING
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);
#endif
}
void Cube::setPos(float x, float y, float z)
{
m_posX = x;
m_posY = y;
m_posZ = z;
}
void Cube::setTexOffs(int a, int b)
{
field_2B4 = a;
field_2B8 = b;
}