XtreemNodes/include/NodeRenderer.h

133 lines
4.0 KiB
C
Raw Normal View History

2022-10-22 17:03:43 +02:00
#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)
2022-10-22 17:03:43 +02:00
{
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
2022-10-22 17:03:43 +02:00
glBegin(GL_QUADS);
// Front
2022-10-29 20:20:24 +02:00
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 - 1))
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + .0F);
}
// Back
2022-10-29 20:20:24 +02:00
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 + 1))
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + 1.0F);
}
// Right
2022-10-29 20:20:24 +02:00
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16 + 1, y, z - block.z * 16))
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
// Left
2022-10-29 20:20:24 +02:00
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16 - 1, y, z - block.z * 16))
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
}
// Bottom
2022-10-29 20:20:24 +02:00
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y - 1, z - block.z * 16) == 0)
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + .0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Top
2022-10-29 20:20:24 +02:00
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y + 1, z - block.z * 16) == 0)
2022-10-22 17:03:43 +02:00
{
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, .0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + .0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(1.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
2022-10-23 23:44:58 +02:00
glTexCoord2f(.0F, 1.0F);
2022-10-22 17:03:43 +02:00
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
glEnd();
return 1;
2022-10-22 17:03:43 +02:00
}
protected:
private:
};
#endif