Skip to content

Commit

Permalink
* More work on the isometric stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Apr 30, 2024
1 parent f7c7446 commit 6bf4ee4
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 18 deletions.
5 changes: 4 additions & 1 deletion source/client/app/Minecraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ void Minecraft::tickInput()
// Minecraft::useAmbientOcclusion = getOptions()->m_bAmbientOcclusion;
// m_pLevelRenderer->allChanged();

m_pGameRenderer->m_bIsometric ^= 1;
if (m_pGameRenderer->m_bIsometric)
m_pGameRenderer->m_isomStage = 100000;
else
m_pGameRenderer->startIsometricRender();
}
#endif
}
Expand Down
106 changes: 89 additions & 17 deletions source/client/renderer/GameRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ void GameRenderer::setupCamera(float f, int i)
float oX = float(Minecraft::width) / float(Minecraft::height) * SCALE;
float oY = SCALE;

glOrtho(-oX, oX, -oY, oY, 0.1f, 500.0f);
xglOrthof(-oX, oX, -oY, oY, 0.1f, 5000.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -100.0f);
glTranslatef(0.0f, 0.0f, -100.0f); // <--- NOT SURE WHY
glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);
}
else
{
Expand Down Expand Up @@ -343,6 +343,9 @@ void GameRenderer::renderNoCamera()

void GameRenderer::setupFog(int i)
{
if (m_bIsometric)
return;

float fog_color[4];
fog_color[0] = field_60;
fog_color[1] = field_64;
Expand Down Expand Up @@ -420,8 +423,6 @@ float GameRenderer::getFov(float f)
Vec3 GameRenderer::getCamPos(float b)
{
if (m_bIsometric) {
Mob* pMob = m_pMinecraft->m_pMobPersp;
return pMob->field_98 + (pMob->m_pos - pMob->field_98) * b;
return Vec3(m_isometricX, m_isometricY, m_isometricZ);
}
else {
Expand Down Expand Up @@ -486,7 +487,7 @@ void GameRenderer::renderLevel(float f)
}
*/

glEnable(GL_FOG);
setFogEnabledIfNeeded(true);
setupFog(1);

if (m_pMinecraft->getOptions()->m_bAmbientOcclusion)
Expand All @@ -506,7 +507,7 @@ void GameRenderer::renderLevel(float f)
prepareAndRenderClouds(pLR, f);

setupFog(0);
glEnable(GL_FOG);
setFogEnabledIfNeeded(true);

m_pMinecraft->m_pTextures->loadAndBindTexture(C_TERRAIN_NAME);
// render the opaque layer
Expand All @@ -517,17 +518,17 @@ void GameRenderer::renderLevel(float f)
glShadeModel(GL_FLAT);
pLR->renderEntities(pMob->getPos(f), &frustumCuller, f);
pPE->render(pMob, f);
}

// @BUG: The original demo calls GL_BLEND. We really should be enabling GL_BLEND.
//glEnable(GL_ALPHA);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
setupFog(0);
// @BUG: The original demo calls GL_BLEND. We really should be enabling GL_BLEND.
//glEnable(GL_ALPHA);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
setupFog(0);

#ifndef ORIGINAL_CODE
glShadeModel(GL_SMOOTH);
glShadeModel(GL_SMOOTH);
#endif
}

glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
Expand Down Expand Up @@ -563,7 +564,7 @@ void GameRenderer::renderLevel(float f)
}
}

glDisable(GL_FOG);
setFogEnabledIfNeeded(false);

if (false) // TODO: Figure out how to enable weather
renderWeather(f);
Expand All @@ -578,12 +579,79 @@ void GameRenderer::renderLevel(float f)
break;
}

resetFogState();

if (bAnaglyph)
glColorMask(true, true, true, false);
}

#define C_ISOM_SIZE (10)
#define C_ISOM_SIZE2 (50)
#define C_MAX_ISOM_STAGE (C_ISOM_SIZE * C_ISOM_SIZE)
void GameRenderer::startIsometricRender()
{
m_bIsometric = true;
m_isomStage = 0;
m_isometricX = 0;
m_isometricY = 0;
m_isometricZ = 0;
}

void GameRenderer::beginIsom(bool &oldDontRenderGui)
{
oldDontRenderGui = false;
if (m_bIsometric && m_isomStage >= C_MAX_ISOM_STAGE) {
m_isomStage = 0;
m_bIsometric = false;
}
else if (m_bIsometric) {
int xInImg = (m_isomStage % C_ISOM_SIZE - C_ISOM_SIZE / 2) * C_ISOM_SIZE2;
int zInImg = (m_isomStage / C_ISOM_SIZE - C_ISOM_SIZE / 2) * C_ISOM_SIZE2;

m_isometricX = 0.0f;
m_isometricY = 70.0f;
m_isometricZ = 250.0f;

// apply the displacement on the X axis
m_isometricX += 2 * xInImg - 2 * zInImg;
m_isometricZ += 2 * zInImg - 2 * xInImg;

m_isomStage++;

oldDontRenderGui = m_pMinecraft->getOptions()->m_bDontRenderGui;
m_pMinecraft->getOptions()->m_bDontRenderGui = true;
}
}

void GameRenderer::endIsom(bool oldDontRenderGui)
{
if (m_bIsometric) {
LOG_I("Saving %d of %d", m_isomStage, C_MAX_ISOM_STAGE);
std::string fn = "IsomShots\\" + std::to_string(m_isomStage) + ".png";
m_pMinecraft->platform()->saveScreenshot(fn, Minecraft::width, Minecraft::height);

m_pMinecraft->getOptions()->m_bDontRenderGui = oldDontRenderGui;
}
}

void GameRenderer::setFogEnabledIfNeeded(bool bEnable)
{
if (m_bIsometric || !bEnable)
glDisable(GL_FOG);
else
glEnable(GL_FOG);
}

void GameRenderer::resetFogState()
{
glDisable(GL_FOG);
}

void GameRenderer::render(float f)
{
bool oldDontRenderGui = false;
beginIsom(oldDontRenderGui);

if (m_pMinecraft->m_pLocalPlayer && m_pMinecraft->m_bGrabbedMouse)
{
Minecraft *pMC = m_pMinecraft;
Expand Down Expand Up @@ -677,8 +745,10 @@ void GameRenderer::render(float f)
renderLevel(f);
if (m_pMinecraft->getOptions()->m_bDontRenderGui)
{
if (!m_pMinecraft->m_pScreen)
if (!m_pMinecraft->m_pScreen) {
endIsom(oldDontRenderGui);
return;
}
}

m_pMinecraft->m_gui.render(f, m_pMinecraft->m_pScreen != nullptr, mouseX, mouseY);
Expand Down Expand Up @@ -716,7 +786,7 @@ void GameRenderer::render(float f)
debugText << "ReMinecraftPE " << m_pMinecraft->getVersionString();
debugText << "\n" << m_shownFPS << " fps, " << m_shownChunkUpdates << " chunk updates";

if (m_pMinecraft->getOptions()->m_bDebugText)
if (m_pMinecraft->getOptions()->m_bDebugText && !m_pMinecraft->getOptions()->m_bDontRenderGui)
{
if (m_pMinecraft->m_pLocalPlayer)
{
Expand Down Expand Up @@ -792,6 +862,8 @@ void GameRenderer::render(float f)
m_shownChunkUpdates = Chunk::updates;
Chunk::updates = 0;
}

endIsom(oldDontRenderGui);
}

void GameRenderer::tick()
Expand Down
8 changes: 8 additions & 0 deletions source/client/renderer/GameRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@ class GameRenderer
void renderItemInHand(float, int);
void prepareAndRenderClouds(LevelRenderer* pLR, float f);
void renderWeather(float f);
void startIsometricRender();

float getFov(float f);

private:
void beginIsom(bool& oldDontRenderGui);
void endIsom(bool oldDontRenderGui);
void setFogEnabledIfNeeded(bool bEnable);
void resetFogState();

public:
ItemInHandRenderer* m_pItemInHandRenderer;
Minecraft* m_pMinecraft;
Expand Down Expand Up @@ -94,5 +101,6 @@ class GameRenderer
float m_isometricX;
float m_isometricY;
float m_isometricZ;
int m_isomStage;
};

0 comments on commit 6bf4ee4

Please sign in to comment.