Initial commit

This commit is contained in:
Functioning Member of Society 2022-10-22 11:03:43 -04:00
commit 48bd114e4b
10 changed files with 8276 additions and 0 deletions

1
Base.c Normal file
View File

@ -0,0 +1 @@
NodeManager nodeManager;

4
Base.cpp Normal file
View File

@ -0,0 +1,4 @@
#include "MapBlock.h"
#include "Base.h"

10
include/Base.h Normal file
View File

@ -0,0 +1,10 @@
//#ifndef BASE
//#define BASE
//#include "NodeRenderer.h"
#include "MapBlock.h"
class NodeManager;
extern NodeManager nodeManager;
//#endif

66
include/MapBlock.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef MAPBLOCK_H
#define MAPBLOCK_H
#include <cstdio>
#include "Base.h"
class NodeManager
{
public:
NodeManager()
{
}
virtual ~NodeManager()
{
}
//8191
void printMapBlock()
{
for(int i = 0; i < 10536; i++)
{
printf("\n[%i] %i", i, mapBlock[i]);
}
}
void addNode(int id, int meta, int x, int y, int z)
{
mapBlock[256 * y + z * 16 + x] = id;
}
bool isAir(int x, int y, int z)
{
return getNodeAt(x, y, z) == 0;
}
int getNodeAt(int x, int y, int z)
{
return x < 16 && z < 16 && x >= 0 && z >= 0 ? mapBlock[256 * y + z * 16 + x] : 0;
}
protected:
private:
int mapBlock[65536];
};
class Block
{
public:
Block(int x, int z)
{
}
int getBlockFromNodeCoordinates(int x, int z)
{
}
};
#endif

131
include/NodeRenderer.h Normal file
View File

@ -0,0 +1,131 @@
#ifndef NODERENDERER_H
#define NODERENDERER_H
#include "Base.h"
#include "MapBlock.h"
#include <GL/glut.h>
class NodeRenderer
{
public:
NodeRenderer()
{
}
virtual ~NodeRenderer()
{
}
renderNode(int x, int y, int z)
{
glBegin(GL_QUADS);
// Front
if(nodeManager.isAir(x, y, z - 1))
{
glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glColor3f(1.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
}
// Back
if(nodeManager.isAir(x, y, z + 1))
{
glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glColor3f(.0F, 1.0F, 1.0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
}
// Right
if(nodeManager.isAir(x + 1, y, z))
{
glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
glColor3f(.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
// Left
if(nodeManager.isAir(x - 1, y, z))
{
glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glColor3f(1.0F, .0F, .0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
}
// Bottom
if(nodeManager.getNodeAt(x, y - 1, z) == 0)
{
glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + .0F);
glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + .0F, y + .0F, z + .0F);
glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + .0F, y + .0F, z + 1.0F);
glColor3f(1.0F, 1.0F, .0F);
glVertex3f(x + 1.0F, y + .0F, z + 1.0F);
}
// Top
if(nodeManager.getNodeAt(x, y + 1, z) == 0)
{
glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + .0F);
glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + .0F);
glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + .0F, y + 1.0F, z + 1.0F);
glColor3f(.0F, .0F, 1.0F);
glVertex3f(x + 1.0F, y + 1.0F, z + 1.0F);
}
glEnd();
}
protected:
private:
};
#endif

6
include/TextureHandler.h Normal file
View File

@ -0,0 +1,6 @@
#include <png.h>
#ifndef TEXTURE_HANDLER
#define TEXTURE_HANDLER
#endif

7898
include/stb_image.h Normal file

File diff suppressed because it is too large Load Diff

160
main.cpp Normal file
View File

@ -0,0 +1,160 @@
#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("Spinning cube");
glClearColor(0, 0, 0, 0);
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;
}

BIN
obj/Debug/Base.o Normal file

Binary file not shown.

BIN
obj/Debug/main.o Normal file

Binary file not shown.