286 lines
12 KiB
C++
286 lines
12 KiB
C++
#ifndef NODERENDERER_H
|
|
#define NODERENDERER_H
|
|
#include "Base.h"
|
|
#include "MapBlock.h"
|
|
#include <GL/glut.h>
|
|
|
|
class NodeRenderer
|
|
{
|
|
public:
|
|
NodeRenderer()
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~NodeRenderer()
|
|
{
|
|
|
|
}
|
|
|
|
int renderNode(int x, int y, int z, int tex)
|
|
{
|
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
|
|
Position2D textureCoordinate;
|
|
textureCoordinate.x = tex - (16 * floor(tex / 16));
|
|
textureCoordinate.z = floor(tex / 16) + 1;
|
|
|
|
|
|
//glColor3f(light, light, light);
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
// Front
|
|
if(blockManager.isAir(x, y, z - 1))
|
|
{
|
|
/*glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F); // Bottom vertices
|
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
|
glVertex3f(x + .0F, y + .0F, z + .0F);*/
|
|
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F); // Bottom vertices
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F); // Bottom vertices
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
}
|
|
|
|
// Back
|
|
if(blockManager.isAir(x, y, z + 1))
|
|
{
|
|
/*glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F);
|
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);*/
|
|
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F);
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F);
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
}
|
|
|
|
// Right
|
|
if(blockManager.isAir(x + 1, y, z))
|
|
{
|
|
/*glTexCoord2f(.0625F * textureCoordinate, .0F);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F);
|
|
glTexCoord2f(.0625F * textureCoordinate, 1.0F);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);*/
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F);
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
|
|
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
}
|
|
|
|
// Left
|
|
if(blockManager.isAir(x - 1, y, z))
|
|
{
|
|
/*glTexCoord2f(.0625F * textureCoordinate, .0F);
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(.6F, .6F, .6F);
|
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
|
|
glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);*/
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3i(100, 100, 100);
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
|
|
|
//glColor3i(255, 255, 255);
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
|
|
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
//glColor3f(1.0F, 1.0F, 1.0F);
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
}
|
|
|
|
// Bottom
|
|
//printf("\n\nx: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
|
if(y > 0 && blockManager.isAir(x, y - 1, z))
|
|
{
|
|
//printf("\nWUT? x: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
|
/*glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);*/
|
|
|
|
glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0F);
|
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
|
|
|
|
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate.x);
|
|
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + .0F, z + 1.0F);
|
|
|
|
|
|
}
|
|
|
|
// Top
|
|
if(blockManager.isNodeClear(x, y + 1, z))
|
|
{
|
|
/*glTexCoord2f(.0F, .0F);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate, .0F);
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate, .0625F * textureCoordinate);
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0F, .0625F * textureCoordinate);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);*/
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + .0F, y + 1.0F, z + .0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * textureCoordinate.z);
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0625F * textureCoordinate.x, .0625F * textureCoordinate.z);
|
|
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
|
|
|
|
glTexCoord2f(.0625F * (textureCoordinate.x - 1), .0625F * (textureCoordinate.z - 1));
|
|
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
|
|
}
|
|
|
|
glEnd();
|
|
return 1;
|
|
}
|
|
|
|
protected:
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
#endif
|