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()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-10-22 20:33:42 +02:00
|
|
|
int renderNode(int x, int y, int z)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 20:43:20 +01:00
|
|
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
|
2022-10-29 20:09:42 +02:00
|
|
|
|
2022-10-30 16:53:41 +01:00
|
|
|
glColor3f(1.0F, 1.0F, 1.0F);
|
2022-10-29 20:09:42 +02:00
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
// Front
|
2022-10-30 22:13:18 +01:00
|
|
|
if(blockManager.isAir(x, y, z - 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-30 17:56:14 +01:00
|
|
|
glColor3f(.6F, .6F, .6F); // Bottom vertices
|
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);
|
2022-10-30 17:56:14 +01:00
|
|
|
glColor3f(1.0F, 1.0F, 1.0F);
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Back
|
2022-10-30 22:13:18 +01:00
|
|
|
if(blockManager.isAir(x, y, z + 1))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 20:43:20 +01: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-30 17:56:14 +01:00
|
|
|
glColor3f(.6F, .6F, .6F);
|
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);
|
2022-10-30 17:56:14 +01:00
|
|
|
glColor3f(1.0F, 1.0F, 1.0F);
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Right
|
2022-10-30 22:05:11 +01:00
|
|
|
if(blockManager.isAir(x + 1, y, z))
|
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-30 17:56:14 +01:00
|
|
|
glColor3f(.6F, .6F, .6F);
|
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-30 17:56:14 +01:00
|
|
|
glColor3f(1.0F, 1.0F, 1.0F);
|
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 + 1.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Left
|
2022-10-30 22:05:11 +01:00
|
|
|
if(blockManager.isAir(x - 1, y, z))
|
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-30 17:56:14 +01:00
|
|
|
glColor3f(.6F, .6F, .6F);
|
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-30 17:56:14 +01:00
|
|
|
glColor3f(1.0F, 1.0F, 1.0F);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bottom
|
2022-10-30 22:05:11 +01:00
|
|
|
//printf("\n\nx: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
|
|
|
if(blockManager.isAir(x, y - 1, z))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 22:05:11 +01:00
|
|
|
//printf("\nWUT? x: %i, y: %i, z: %i, VALUE: %s", x, y, z, blockManager.isAir(x, y - 1, z) ? "true" : "false");
|
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-30 22:05:11 +01:00
|
|
|
if(blockManager.isAir(x, y + 1, z))
|
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);
|
2022-10-30 22:05:11 +01:00
|
|
|
}
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
glEnd();
|
2022-10-22 20:33:42 +02:00
|
|
|
return 1;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|