#include #include #include "Utilities.h" #include "MapBlock.h" #include "Base.h" #include "NodeRenderer.h" #include "TextureHandler.h" #include #include #include "FastNoiseLite.h" #include //#include //#include NodeRenderer renderer; //BlockManager blockManager; NodeManager nodeManager; NodeManager nodeManager1; BlockManager blockManager; TextureHandler textureHandler; GLfloat playerX = 0; GLfloat playerY = 30; GLfloat playerZ = 100; GLfloat playerRotX = 0; GLfloat playerRotY = 0; void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-playerX, -playerY, -playerZ); glRotatef(playerRotX, 1.0F, .0F, .0F); glRotatef(playerRotY, .0F, 1.0F, .0F); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBegin(GL_QUADS); for(int x = 0; x < 128; x++) { for(int z = 0; z < 128; z++) { for(int y = 0; y < 64; y++) { Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // Math explanation for future reference: // The if statement below checks if the node at the coordinate is greater than 0 (0 = air), the x and z coordinates // need to be have block.[AXIS] * 16 subtracted from them so that the coordinates passed to the function are local // block coordinates instead of global node coordinates (e.g. 1, and not 17) if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) > 0) { textureHandler.getTextureForNode(x, y, z); renderer.renderNode(x, y, z); } } } } glEnd(); glFlush(); glutSwapBuffers(); /* sf::Vector2i lastMousePos = sf::Vector2i(0, 0); const sf::Window& window = nullptr; sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos; lastMousePos = sf::Mouse::getPosition(window);*/ glutPostRedisplay(); } void reshape(int width, int height) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(20, width / (float) height, 5, 512.0F); glViewport(0, 0, width, height); glMatrixMode(GL_MODELVIEW); glutPostRedisplay(); } void updateTimer() { //glutTimerFunc(30, &updateTimer, 0); } void KeyboardFunc(unsigned char key, int x, int y) { if(key == 'a') { playerX += .8F; } if(key == 'd') { playerX -= .8F; } if(key == 'w') { playerX += .8; } if(key == 's') { playerX -= sin(Utilities::degToRad(playerRotY)); playerY += sin(Utilities::degToRad(playerRotX)); playerZ += cos(Utilities::degToRad(playerRotY)); } if(key == 'q') { playerY += .1F; } if(key == 'e') { playerY -= .1F; } if(key == 't') { playerRotX -= .8F; } if(key == 'g') { playerRotX += .8F; } if(key == 'f') { playerRotY -= .8F; } if(key == 'h') { playerRotY += .8F; } 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); // Load textures textureHandler.loadAllTextures(); FastNoiseLite fnl; fnl.SetSeed(1337); fnl.SetNoiseType(FastNoiseLite::NoiseType_Value); fnl.SetFrequency(.01F); for(int bx = 0; bx < 8; bx++) { for(int bz = 0; bz < 8; bz++) { for(int x = 0; x < 16; x++) { for(int z = 0; z < 16; z++) { for(int y = 0; y < 48 * abs(fnl.GetNoise((float)x + (16 * bx), (float)z + (16 * bz))) + 2; y++) { blockManager.mapBlocks[bx][bz].addNode(1, 0, x, y, z); //printf("\nx: %i, z: %i", x + (16 * bx), z + (16 * bz)); //printf("\nGet node at: %i\n Is air: %i", nodeManager.getNodeAt(x, y + 1, z) == 0, nodeManager.isAir(x, y + 1, z)); } } } } } /* for(int x = 0; x < 32; x++) { for(int z = 0; z < 16; z++) { for(int y = 0; y < 16; y++) { Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); printf("x - (blockX * 16): %i | X: %i, Y: %i, Z: %i, blockX: %i, blockZ: %i nodeAt: %i\n", x - (block.x * 16), x, y, z, block.x, block.z, blockManager.mapBlocks[block.x][block.z].getNodeAt(x - (block.x * 16), y, z)); } } } */ updateTimer(); glutDisplayFunc(&display); glutReshapeFunc(&reshape); glutKeyboardFunc(&KeyboardFunc); glutMainLoop(); return 0; }