Minor changes
This commit is contained in:
parent
1965b97c19
commit
922826da0b
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,2 @@
|
|||||||
XtreemMiner.cbp
|
|
||||||
XtreemMiner.depend
|
|
||||||
XtreemMiner.layout
|
|
||||||
bin
|
bin
|
||||||
obj
|
obj
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1667085219 source:c:\development\xtreemminer\main.cpp
|
1667141044 source:c:\development\xtreemminer\main.cpp
|
||||||
<stdlib.h>
|
<stdlib.h>
|
||||||
<GL/glut.h>
|
<GL/glut.h>
|
||||||
"Utilities.h"
|
"Utilities.h"
|
||||||
@ -12,12 +12,12 @@
|
|||||||
"FastNoiseLite.h"
|
"FastNoiseLite.h"
|
||||||
<random>
|
<random>
|
||||||
|
|
||||||
1667067326 c:\development\xtreemminer\include\noderenderer.h
|
1667140765 c:\development\xtreemminer\include\noderenderer.h
|
||||||
"Base.h"
|
"Base.h"
|
||||||
"MapBlock.h"
|
"MapBlock.h"
|
||||||
<GL/glut.h>
|
<GL/glut.h>
|
||||||
|
|
||||||
1667014762 c:\development\xtreemminer\include\mapblock.h
|
1667141085 c:\development\xtreemminer\include\mapblock.h
|
||||||
"Base.h"
|
"Base.h"
|
||||||
<math.h>
|
<math.h>
|
||||||
|
|
||||||
@ -27,7 +27,7 @@
|
|||||||
"MapBlock.h"
|
"MapBlock.h"
|
||||||
"Base.h"
|
"Base.h"
|
||||||
|
|
||||||
1667088753 c:\development\xtreemminer\include\texturehandler.h
|
1667096344 c:\development\xtreemminer\include\texturehandler.h
|
||||||
"stb_image.h"
|
"stb_image.h"
|
||||||
"Base.h"
|
"Base.h"
|
||||||
|
|
||||||
|
@ -7,22 +7,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NodeManager
|
class MapBlock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int blockX;
|
int blockX;
|
||||||
int blockZ;
|
int blockZ;
|
||||||
|
|
||||||
NodeManager()
|
MapBlock()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~NodeManager()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void addNode(int id, int meta, int x, int y, int z)
|
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)
|
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:
|
protected:
|
||||||
@ -48,7 +44,7 @@ class NodeManager
|
|||||||
class BlockManager
|
class BlockManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NodeManager mapBlocks[8][8]; // 8 x 8 blocks
|
MapBlock mapBlocks[16][16]; // 8 x 8 blocks
|
||||||
|
|
||||||
BlockManager()
|
BlockManager()
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@ class NodeRenderer
|
|||||||
{
|
{
|
||||||
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z); // The block the node at (x, y, z) is in
|
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);
|
glBegin(GL_QUADS);
|
||||||
// Front
|
// Front
|
||||||
@ -35,10 +36,13 @@ class NodeRenderer
|
|||||||
glTexCoord2f(1.0F, 1.0F);
|
glTexCoord2f(1.0F, 1.0F);
|
||||||
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
glVertex3f(x + 1.0F, y + .0F, z + .0F);
|
||||||
|
|
||||||
|
//glColor3f(.0F, .0F, .8F);
|
||||||
glTexCoord2f(.0F, 1.0F);
|
glTexCoord2f(.0F, 1.0F);
|
||||||
glVertex3f(x + .0F, y + .0F, z + .0F);
|
glVertex3f(x + .0F, y + .0F, z + .0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glColor3f(1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
// Back
|
// Back
|
||||||
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 + 1))
|
if(blockManager.mapBlocks[block.x][block.z].isAir(x - block.x * 16, y, z - block.z * 16 + 1))
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ class TextureHandler
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
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);
|
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);
|
glGenTextures(1, &textures1);
|
||||||
glBindTexture(GL_TEXTURE_2D, textures1);
|
glBindTexture(GL_TEXTURE_2D, textures1);
|
||||||
|
|
||||||
@ -52,17 +52,16 @@ class TextureHandler
|
|||||||
|
|
||||||
void getTextureForNode(int x, int y, int z)
|
void getTextureForNode(int x, int y, int z)
|
||||||
{
|
{
|
||||||
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
||||||
|
if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) == 1)
|
||||||
//if(nodeManager.getNodeAt(x, y, z) == 1)
|
{
|
||||||
//{
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textures);
|
glBindTexture(GL_TEXTURE_2D, textures);
|
||||||
//}
|
}
|
||||||
|
|
||||||
//else if(nodeManager.getNodeAt(x, y, z) == 2)
|
else if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) == 2)
|
||||||
//{
|
{
|
||||||
//glBindTexture(GL_TEXTURE_2D, textures1);
|
glBindTexture(GL_TEXTURE_2D, textures1);
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
main.cpp
46
main.cpp
@ -14,14 +14,13 @@
|
|||||||
|
|
||||||
NodeRenderer renderer;
|
NodeRenderer renderer;
|
||||||
//BlockManager blockManager;
|
//BlockManager blockManager;
|
||||||
NodeManager nodeManager;
|
|
||||||
NodeManager nodeManager1;
|
|
||||||
BlockManager blockManager;
|
BlockManager blockManager;
|
||||||
TextureHandler textureHandler;
|
TextureHandler textureHandler;
|
||||||
|
|
||||||
GLfloat playerX = 0;
|
GLfloat playerX = 0;
|
||||||
GLfloat playerY = 30;
|
GLfloat playerY = -30;
|
||||||
GLfloat playerZ = 100;
|
GLfloat playerZ = -100;
|
||||||
GLfloat playerRotX = 0;
|
GLfloat playerRotX = 0;
|
||||||
GLfloat playerRotY = 0;
|
GLfloat playerRotY = 0;
|
||||||
|
|
||||||
@ -32,12 +31,13 @@ void display()
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
glTranslatef(-playerX, -playerY, -playerZ);
|
|
||||||
glRotatef(playerRotX, 1.0F, .0F, .0F);
|
glRotatef(playerRotX, 1.0F, .0F, .0F);
|
||||||
glRotatef(playerRotY, .0F, 1.0F, .0F);
|
glRotatef(playerRotY, .0F, 1.0F, .0F);
|
||||||
|
glTranslatef(playerX, playerY, playerZ);
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
//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);
|
glBegin(GL_QUADS);
|
||||||
@ -73,7 +73,7 @@ void display()
|
|||||||
const sf::Window& window = nullptr;
|
const sf::Window& window = nullptr;
|
||||||
sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos;
|
sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos;
|
||||||
lastMousePos = sf::Mouse::getPosition(window);*/
|
lastMousePos = sf::Mouse::getPosition(window);*/
|
||||||
glutPostRedisplay();
|
//glutPostRedisplay();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,9 +90,10 @@ void reshape(int width, int height)
|
|||||||
glutPostRedisplay();
|
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)
|
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')
|
if(key == 'w')
|
||||||
{
|
{
|
||||||
playerX += .8;
|
playerZ += .8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 's')
|
if(key == 's')
|
||||||
{
|
{
|
||||||
playerX -= sin(Utilities::degToRad(playerRotY));
|
playerZ -= .8;
|
||||||
playerY += sin(Utilities::degToRad(playerRotX));
|
|
||||||
playerZ += cos(Utilities::degToRad(playerRotY));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 'q')
|
if(key == 'q')
|
||||||
{
|
{
|
||||||
playerY += .1F;
|
playerY += .8F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 'e')
|
if(key == 'e')
|
||||||
{
|
{
|
||||||
playerY -= .1F;
|
playerY -= .8F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 't')
|
if(key == 't')
|
||||||
@ -175,7 +174,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
glClearColor(.2, .7, .8 , 255);
|
glClearColor(.2, .7, .8 , 255);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
/*glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_FRONT);
|
||||||
|
glFrontFace(GL_CCW);*/
|
||||||
|
|
||||||
// Load textures
|
// Load textures
|
||||||
textureHandler.loadAllTextures();
|
textureHandler.loadAllTextures();
|
||||||
@ -183,12 +185,12 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
FastNoiseLite fnl;
|
FastNoiseLite fnl;
|
||||||
fnl.SetSeed(1337);
|
fnl.SetSeed(1337);
|
||||||
fnl.SetNoiseType(FastNoiseLite::NoiseType_Value);
|
fnl.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
||||||
fnl.SetFrequency(.01F);
|
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++)
|
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++)
|
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);
|
glutDisplayFunc(&display);
|
||||||
glutReshapeFunc(&reshape);
|
glutReshapeFunc(&reshape);
|
||||||
glutKeyboardFunc(&KeyboardFunc);
|
glutKeyboardFunc(&KeyboardFunc);
|
||||||
|
Loading…
Reference in New Issue
Block a user