XtreemNodes/main.cpp

161 lines
2.6 KiB
C++

#include <stdlib.h>
#include <GL/glut.h>
#include "include/Base.h"
#include "NodeRenderer.h"
#include <cstdio>
#include <random>
NodeRenderer renderer;
NodeManager nodeManager;
GLfloat playerX = 0;
GLfloat playerY = -30;
GLfloat playerZ = -100;
GLfloat playerRotX = 0;
void DisplayFunc()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(playerX, playerY, playerZ);
//glTranslatef(playerX, 0, - 1 - alpha / 4);
glRotatef(playerRotX, .0F, 1.0F, .0F);
//glRotatef(alpha * 1.1, 0, 1, 0);
glBegin(GL_QUADS);
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
if(nodeManager.getNodeAt(x, y, z) == 1)
renderer.renderNode(x, y, z);
}
}
}
glEnd();
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
void ReshapeFunc(int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(20, width / (float) height, 5, 150);
glViewport(0, 0, width, height);
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}
void KeyboardFunc(unsigned char key, int x, int y)
{
if(key == 'a')
{
playerX += .8F;
}
if(key == 'd')
{
playerX -= .8F;
}
if(key == 'w')
{
playerZ += .8F;
}
if(key == 's')
{
playerZ -= .8F;
}
if(key == 'q')
{
playerY += .1F;
}
if(key == 'e')
{
playerY -= .1F;
}
if(key == 'f')
{
playerRotX -= .8F;
}
if(key == 'h')
{
playerRotX += .8F;
}
if(key == 'x')
{
nodeManager.printMapBlock();
}
if(key == 27)
{
exit(0);
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software");
glClearColor(.2, .7, .8, 255);
glEnable(GL_DEPTH_TEST);
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
for(int y = 0; y < 256; y++)
{
nodeManager.addNode(rand() % 2, 0, x, y, z);
//printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z));
}
}
}
glutDisplayFunc(&DisplayFunc);
glutReshapeFunc(&ReshapeFunc);
glutKeyboardFunc(&KeyboardFunc);
glutMainLoop();
return 0;
}