Compare commits
No commits in common. "1d1aad04cf34d8df4ac5ba5d6973ae532f5a9b4b" and "1965b97c197f7380225b124619324b97e38c2547" have entirely different histories.
1d1aad04cf
...
1965b97c19
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
|||||||
|
XtreemMiner.cbp
|
||||||
|
XtreemMiner.depend
|
||||||
|
XtreemMiner.layout
|
||||||
bin
|
bin
|
||||||
obj
|
obj
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1667141044 source:c:\development\xtreemminer\main.cpp
|
1667085219 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>
|
||||||
|
|
||||||
1667140765 c:\development\xtreemminer\include\noderenderer.h
|
1667067326 c:\development\xtreemminer\include\noderenderer.h
|
||||||
"Base.h"
|
"Base.h"
|
||||||
"MapBlock.h"
|
"MapBlock.h"
|
||||||
<GL/glut.h>
|
<GL/glut.h>
|
||||||
|
|
||||||
1667141085 c:\development\xtreemminer\include\mapblock.h
|
1667014762 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"
|
||||||
|
|
||||||
1667096344 c:\development\xtreemminer\include\texturehandler.h
|
1667088753 c:\development\xtreemminer\include\texturehandler.h
|
||||||
"stb_image.h"
|
"stb_image.h"
|
||||||
"Base.h"
|
"Base.h"
|
||||||
|
|
||||||
|
BIN
data/img/oak.png
BIN
data/img/oak.png
Binary file not shown.
Before Width: | Height: | Size: 877 B After Width: | Height: | Size: 744 B |
@ -7,18 +7,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MapBlock
|
class NodeManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int blockX;
|
int blockX;
|
||||||
int blockZ;
|
int blockZ;
|
||||||
|
|
||||||
MapBlock()
|
NodeManager()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
@ -32,7 +36,7 @@ class MapBlock
|
|||||||
|
|
||||||
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] : 1;
|
return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -44,7 +48,7 @@ class MapBlock
|
|||||||
class BlockManager
|
class BlockManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MapBlock mapBlocks[16][16]; // 8 x 8 blocks
|
NodeManager mapBlocks[8][8]; // 8 x 8 blocks
|
||||||
|
|
||||||
BlockManager()
|
BlockManager()
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,6 @@ 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
|
||||||
@ -36,13 +35,10 @@ 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/oak.png");
|
imageData1 = loadTexture("data/img/iron.png");
|
||||||
glGenTextures(1, &textures1);
|
glGenTextures(1, &textures1);
|
||||||
glBindTexture(GL_TEXTURE_2D, textures1);
|
glBindTexture(GL_TEXTURE_2D, textures1);
|
||||||
|
|
||||||
@ -52,16 +52,17 @@ 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)
|
|
||||||
{
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textures);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(blockManager.mapBlocks[block.x][block.z].getNodeAt(x - block.x * 16, y, z - block.z * 16) == 2)
|
|
||||||
{
|
//if(nodeManager.getNodeAt(x, y, z) == 1)
|
||||||
glBindTexture(GL_TEXTURE_2D, textures1);
|
//{
|
||||||
}
|
glBindTexture(GL_TEXTURE_2D, textures);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//else if(nodeManager.getNodeAt(x, y, z) == 2)
|
||||||
|
//{
|
||||||
|
//glBindTexture(GL_TEXTURE_2D, textures1);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
main.cpp
46
main.cpp
@ -14,13 +14,14 @@
|
|||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@ -31,13 +32,12 @@ 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_MODULATE);
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
||||||
|
|
||||||
|
|
||||||
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,10 +90,9 @@ void reshape(int width, int height)
|
|||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateTimer(int time)
|
void updateTimer()
|
||||||
{
|
{
|
||||||
glutPostRedisplay();
|
//glutTimerFunc(30, &updateTimer, 0);
|
||||||
glutTimerFunc(30, &updateTimer, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardFunc(unsigned char key, int x, int y)
|
void KeyboardFunc(unsigned char key, int x, int y)
|
||||||
@ -110,22 +109,24 @@ void KeyboardFunc(unsigned char key, int x, int y)
|
|||||||
|
|
||||||
if(key == 'w')
|
if(key == 'w')
|
||||||
{
|
{
|
||||||
playerZ += .8;
|
playerX += .8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 's')
|
if(key == 's')
|
||||||
{
|
{
|
||||||
playerZ -= .8;
|
playerX -= sin(Utilities::degToRad(playerRotY));
|
||||||
|
playerY += sin(Utilities::degToRad(playerRotX));
|
||||||
|
playerZ += cos(Utilities::degToRad(playerRotY));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 'q')
|
if(key == 'q')
|
||||||
{
|
{
|
||||||
playerY += .8F;
|
playerY += .1F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 'e')
|
if(key == 'e')
|
||||||
{
|
{
|
||||||
playerY -= .8F;
|
playerY -= .1F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == 't')
|
if(key == 't')
|
||||||
@ -174,10 +175,7 @@ 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();
|
||||||
@ -185,12 +183,12 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
FastNoiseLite fnl;
|
FastNoiseLite fnl;
|
||||||
fnl.SetSeed(1337);
|
fnl.SetSeed(1337);
|
||||||
fnl.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
fnl.SetNoiseType(FastNoiseLite::NoiseType_Value);
|
||||||
fnl.SetFrequency(.01F);
|
fnl.SetFrequency(.01F);
|
||||||
|
|
||||||
for(int bx = 0; bx < 16; bx++)
|
for(int bx = 0; bx < 8; bx++)
|
||||||
{
|
{
|
||||||
for(int bz = 0; bz < 16; bz++)
|
for(int bz = 0; bz < 8; bz++)
|
||||||
{
|
{
|
||||||
for(int x = 0; x < 16; x++)
|
for(int x = 0; x < 16; x++)
|
||||||
{
|
{
|
||||||
@ -198,7 +196,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(y > 30 ? 1 : 2, 0, x, y, z);
|
blockManager.mapBlocks[bx][bz].addNode(1, 0, x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -227,7 +225,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
updateTimer(0);
|
updateTimer();
|
||||||
glutDisplayFunc(&display);
|
glutDisplayFunc(&display);
|
||||||
glutReshapeFunc(&reshape);
|
glutReshapeFunc(&reshape);
|
||||||
glutKeyboardFunc(&KeyboardFunc);
|
glutKeyboardFunc(&KeyboardFunc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user