diff --git a/.gitignore b/.gitignore index 08e2f43..1746e32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,2 @@ -XtreemMiner.cbp -XtreemMiner.depend -XtreemMiner.layout bin obj diff --git a/XtreemNodes.depend b/XtreemNodes.depend index 3982a17..e5acf01 100644 --- a/XtreemNodes.depend +++ b/XtreemNodes.depend @@ -1,5 +1,5 @@ # depslib dependency file v1.0 -1667085219 source:c:\development\xtreemminer\main.cpp +1667141044 source:c:\development\xtreemminer\main.cpp "Utilities.h" @@ -12,12 +12,12 @@ "FastNoiseLite.h" -1667067326 c:\development\xtreemminer\include\noderenderer.h +1667140765 c:\development\xtreemminer\include\noderenderer.h "Base.h" "MapBlock.h" -1667014762 c:\development\xtreemminer\include\mapblock.h +1667141085 c:\development\xtreemminer\include\mapblock.h "Base.h" @@ -27,7 +27,7 @@ "MapBlock.h" "Base.h" -1667088753 c:\development\xtreemminer\include\texturehandler.h +1667096344 c:\development\xtreemminer\include\texturehandler.h "stb_image.h" "Base.h" diff --git a/include/MapBlock.h b/include/MapBlock.h index d162067..645cfac 100644 --- a/include/MapBlock.h +++ b/include/MapBlock.h @@ -7,22 +7,18 @@ -class NodeManager +class MapBlock { public: int blockX; int blockZ; - NodeManager() + MapBlock() { } - virtual ~NodeManager() - { - - } void addNode(int id, int meta, int x, int y, int z) { @@ -36,7 +32,7 @@ class NodeManager int getNodeAt(int x, int y, int z) { - return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0; + return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 1; } protected: @@ -48,7 +44,7 @@ class NodeManager class BlockManager { public: - NodeManager mapBlocks[8][8]; // 8 x 8 blocks + MapBlock mapBlocks[16][16]; // 8 x 8 blocks BlockManager() { diff --git a/include/NodeRenderer.h b/include/NodeRenderer.h index 02e1179..3713752 100644 --- a/include/NodeRenderer.h +++ b/include/NodeRenderer.h @@ -21,6 +21,7 @@ class NodeRenderer { Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in + glColor3f(1.0F, 1.0F, 1.0F); glBegin(GL_QUADS); // Front @@ -35,10 +36,13 @@ class NodeRenderer glTexCoord2f(1.0F, 1.0F); glVertex3f(x + 1.0F, y + .0F, z + .0F); + //glColor3f(.0F, .0F, .8F); glTexCoord2f(.0F, 1.0F); glVertex3f(x + .0F, y + .0F, z + .0F); } + glColor3f(1.0F, 1.0F, 1.0F); + // Back if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 + 1)) { diff --git a/include/TextureHandler.h b/include/TextureHandler.h index 0260641..d9a9e64 100644 --- a/include/TextureHandler.h +++ b/include/TextureHandler.h @@ -39,7 +39,7 @@ class TextureHandler glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); - imageData1 = loadTexture("data/img/iron.png"); + imageData1 = loadTexture("data/img/oak.png"); glGenTextures(1, &textures1); glBindTexture(GL_TEXTURE_2D, textures1); @@ -52,17 +52,16 @@ class TextureHandler void getTextureForNode(int x, int y, int z) { - - - //if(nodeManager.getNodeAt(x, y, z) == 1) - //{ + Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); + if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) == 1) + { glBindTexture(GL_TEXTURE_2D, textures); - //} + } - //else if(nodeManager.getNodeAt(x, y, z) == 2) - //{ - //glBindTexture(GL_TEXTURE_2D, textures1); - //} + else if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) == 2) + { + glBindTexture(GL_TEXTURE_2D, textures1); + } } diff --git a/main.cpp b/main.cpp index 94d3738..14a97dd 100644 --- a/main.cpp +++ b/main.cpp @@ -14,14 +14,13 @@ NodeRenderer renderer; //BlockManager blockManager; -NodeManager nodeManager; -NodeManager nodeManager1; + BlockManager blockManager; TextureHandler textureHandler; GLfloat playerX = 0; -GLfloat playerY = 30; -GLfloat playerZ = 100; +GLfloat playerY = -30; +GLfloat playerZ = -100; GLfloat playerRotX = 0; GLfloat playerRotY = 0; @@ -32,12 +31,13 @@ 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); + glTranslatef(playerX, playerY, playerZ); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBegin(GL_QUADS); @@ -73,7 +73,7 @@ void display() const sf::Window& window = nullptr; sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos; lastMousePos = sf::Mouse::getPosition(window);*/ - glutPostRedisplay(); + //glutPostRedisplay(); } @@ -90,9 +90,10 @@ void reshape(int width, int height) glutPostRedisplay(); } -void updateTimer() +void updateTimer(int time) { - //glutTimerFunc(30, &updateTimer, 0); + glutPostRedisplay(); + glutTimerFunc(30, &updateTimer, 0); } void KeyboardFunc(unsigned char key, int x, int y) @@ -109,24 +110,22 @@ void KeyboardFunc(unsigned char key, int x, int y) if(key == 'w') { - playerX += .8; + playerZ += .8; } if(key == 's') { - playerX -= sin(Utilities::degToRad(playerRotY)); - playerY += sin(Utilities::degToRad(playerRotX)); - playerZ += cos(Utilities::degToRad(playerRotY)); + playerZ -= .8; } if(key == 'q') { - playerY += .1F; + playerY += .8F; } if(key == 'e') { - playerY -= .1F; + playerY -= .8F; } if(key == 't') @@ -175,7 +174,10 @@ int main(int argc, char **argv) glClearColor(.2, .7, .8 , 255); glEnable(GL_DEPTH_TEST); - + glEnable(GL_TEXTURE_2D); + /*glEnable(GL_CULL_FACE); + glCullFace(GL_FRONT); + glFrontFace(GL_CCW);*/ // Load textures textureHandler.loadAllTextures(); @@ -183,12 +185,12 @@ int main(int argc, char **argv) FastNoiseLite fnl; fnl.SetSeed(1337); - fnl.SetNoiseType(FastNoiseLite::NoiseType_Value); + fnl.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2); fnl.SetFrequency(.01F); - for(int bx = 0; bx < 8; bx++) + for(int bx = 0; bx < 16; bx++) { - for(int bz = 0; bz < 8; bz++) + for(int bz = 0; bz < 16; bz++) { for(int x = 0; x < 16; x++) { @@ -196,7 +198,7 @@ int main(int argc, char **argv) { 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); + blockManager.mapBlocks[bx][bz].addNode(y > 30 ? 1 : 2, 0, x, y, z); } } } @@ -225,7 +227,7 @@ int main(int argc, char **argv) - updateTimer(); + updateTimer(0); glutDisplayFunc(&display); glutReshapeFunc(&reshape); glutKeyboardFunc(&KeyboardFunc);