XtreemNodes/include/NodeRenderer.h
2022-10-29 14:20:24 -04:00

133 lines
4.0 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)
{
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
glBegin(GL_QUADS);
// Front
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 - 1))
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
}
// Back
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 + 1))
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
}
// Right
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16 + 1, y, z - block.z * 16))
{
glTexCoord2f(1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
// Left
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16 - 1, y, z - block.z * 16))
{
glTexCoord2f(1.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
}
// Bottom
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y - 1, z - block.z * 16) == 0)
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Top
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y + 1, z - block.z * 16) == 0)
{
glTexCoord2f(.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glTexCoord2f(1.0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glTexCoord2f(.0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
glEnd();
return 1;
}
protected:
private:
};
#endif