2022-10-22 17:03:43 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <GL/glut.h>
|
2022-10-30 01:17:58 +02:00
|
|
|
#include "Utilities.h"
|
2022-10-23 23:44:58 +02:00
|
|
|
#include "MapBlock.h"
|
|
|
|
#include "Base.h"
|
2022-10-22 17:03:43 +02:00
|
|
|
#include "NodeRenderer.h"
|
2022-10-23 23:44:58 +02:00
|
|
|
#include "TextureHandler.h"
|
2022-10-30 01:17:58 +02:00
|
|
|
#include <math.h>
|
2022-10-22 17:03:43 +02:00
|
|
|
#include <cstdio>
|
2022-10-30 01:17:58 +02:00
|
|
|
#include "FastNoiseLite.h"
|
2022-10-22 17:03:43 +02:00
|
|
|
#include <random>
|
2022-10-30 23:19:59 +01:00
|
|
|
#include <SFML/Window.hpp>
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
NodeRenderer renderer;
|
2022-10-26 23:18:33 +02:00
|
|
|
//BlockManager blockManager;
|
2022-10-30 16:53:41 +01:00
|
|
|
|
2022-10-29 05:47:09 +02:00
|
|
|
BlockManager blockManager;
|
2022-10-23 23:44:58 +02:00
|
|
|
TextureHandler textureHandler;
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
GLfloat playerX = 0;
|
2022-10-30 16:53:41 +01:00
|
|
|
GLfloat playerY = -30;
|
|
|
|
GLfloat playerZ = -100;
|
2022-10-22 17:03:43 +02:00
|
|
|
GLfloat playerRotX = 0;
|
2022-10-30 01:17:58 +02:00
|
|
|
GLfloat playerRotY = 0;
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-10-23 23:44:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
void display()
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2022-10-30 16:53:41 +01:00
|
|
|
|
2022-10-30 01:17:58 +02:00
|
|
|
glRotatef(playerRotX, 1.0F, .0F, .0F);
|
|
|
|
glRotatef(playerRotY, .0F, 1.0F, .0F);
|
2022-10-30 16:53:41 +01:00
|
|
|
glTranslatef(playerX, playerY, playerZ);
|
2022-10-30 01:17:58 +02:00
|
|
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
2022-10-30 16:53:41 +01:00
|
|
|
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
2022-10-29 20:09:42 +02:00
|
|
|
|
2022-11-01 00:06:45 +01:00
|
|
|
for(int x = 0; x < 100; x++)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
2022-10-30 20:43:20 +01:00
|
|
|
for(int y = 0; y < 64; y++)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
2022-11-01 00:06:45 +01:00
|
|
|
for(int z = 0; z < 100; z++)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
2022-10-30 17:56:14 +01:00
|
|
|
if(blockManager.getNodeAt(x, y, z) > 0)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
|
|
|
textureHandler.getTextureForNode(x, y, z);
|
|
|
|
renderer.renderNode(x, y, z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
glutSwapBuffers();
|
2022-10-29 20:09:42 +02:00
|
|
|
/*
|
2022-10-29 05:55:27 +02:00
|
|
|
sf::Vector2i lastMousePos = sf::Vector2i(0, 0);
|
2022-10-29 20:09:42 +02:00
|
|
|
const sf::Window& window = nullptr;
|
|
|
|
sf::Vector2i mouseDelta = sf::Mouse::getPosition(window) - lastMousePos;
|
|
|
|
lastMousePos = sf::Mouse::getPosition(window);*/
|
2022-10-30 16:53:41 +01:00
|
|
|
//glutPostRedisplay();
|
2022-10-30 01:17:58 +02:00
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-23 23:44:58 +02:00
|
|
|
void reshape(int width, int height)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
|
|
|
|
glLoadIdentity();
|
2022-10-30 20:43:20 +01:00
|
|
|
gluPerspective(30, width / (float) height, 5, 512.0F);
|
2022-10-22 17:03:43 +02:00
|
|
|
glViewport(0, 0, width, height);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glutPostRedisplay();
|
|
|
|
}
|
|
|
|
|
2022-10-30 16:53:41 +01:00
|
|
|
void updateTimer(int time)
|
2022-10-29 05:47:09 +02:00
|
|
|
{
|
2022-10-30 23:19:59 +01:00
|
|
|
// Movement
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 16:53:41 +01:00
|
|
|
playerZ += .8;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 16:53:41 +01:00
|
|
|
playerZ -= .8;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 23:19:59 +01:00
|
|
|
playerX += .8;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 23:19:59 +01:00
|
|
|
playerX -= .8;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-11-01 00:06:45 +01:00
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LShift))
|
|
|
|
{
|
2022-11-02 02:21:18 +01:00
|
|
|
playerY += .8;
|
2022-11-01 00:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
|
|
|
|
{
|
2022-11-02 02:21:18 +01:00
|
|
|
playerY -= .8;
|
2022-11-01 00:06:45 +01:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
// Rotation
|
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-11-02 02:21:18 +01:00
|
|
|
playerRotY -= 1.8;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-11-02 02:21:18 +01:00
|
|
|
playerRotY += 1.8;
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
2022-10-30 01:17:58 +02:00
|
|
|
{
|
2022-11-02 02:21:18 +01:00
|
|
|
playerRotX -= 1.8;
|
2022-10-30 01:17:58 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
|
2022-10-30 01:17:58 +02:00
|
|
|
{
|
2022-11-02 02:21:18 +01:00
|
|
|
playerRotX += 1.8;
|
2022-10-30 01:17:58 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2022-10-30 23:19:59 +01:00
|
|
|
glutPostRedisplay();
|
|
|
|
glutTimerFunc(30, &updateTimer, 0);
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
glutInit(&argc, argv);
|
|
|
|
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
|
|
|
glutInitWindowSize(800, 600);
|
2022-10-22 20:33:42 +02:00
|
|
|
glutCreateWindow("XtreemNodes Engine - By MCL Software and Cube Software");
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
glClearColor(.4, .7, .8 , 255);
|
2022-10-22 17:03:43 +02:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
2022-10-30 16:53:41 +01:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2022-10-30 17:56:14 +01:00
|
|
|
//glEnable(GL_CULL_FACE);
|
|
|
|
//glCullFace(GL_FRONT);
|
|
|
|
//glFrontFace(GL_CCW);
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-10-23 23:44:58 +02:00
|
|
|
// Load textures
|
|
|
|
textureHandler.loadAllTextures();
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-10-30 17:56:14 +01:00
|
|
|
FastNoiseLite perlin, os, cellular;
|
2022-10-30 20:43:20 +01:00
|
|
|
int seed = 138;
|
2022-10-30 17:56:14 +01:00
|
|
|
perlin.SetSeed(seed);
|
|
|
|
perlin.SetNoiseType(FastNoiseLite::NoiseType_Perlin);
|
|
|
|
perlin.SetFrequency(.01F);
|
|
|
|
|
|
|
|
os.SetSeed(seed);
|
|
|
|
os.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);
|
|
|
|
os.SetFrequency(.01F);
|
|
|
|
|
|
|
|
cellular.SetSeed(seed);
|
|
|
|
cellular.SetNoiseType(FastNoiseLite::NoiseType_Cellular);
|
|
|
|
cellular.SetFrequency(.1F);
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-11-01 00:06:45 +01:00
|
|
|
for(int bx = 0; bx < 8; bx++)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
2022-11-01 00:06:45 +01:00
|
|
|
for(int bz = 0; bz < 8; bz++)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
2022-10-29 20:09:42 +02:00
|
|
|
for(int x = 0; x < 16; x++)
|
2022-10-23 23:44:58 +02:00
|
|
|
{
|
2022-10-29 20:09:42 +02:00
|
|
|
for(int z = 0; z < 16; z++)
|
|
|
|
{
|
2022-10-30 17:56:14 +01:00
|
|
|
float cX = (float)x + (16 * bx);
|
|
|
|
float cZ = (float)z + (16 * bz);
|
2022-11-02 02:21:18 +01:00
|
|
|
for(int y = 0; y < 48 * abs(perlin.GetNoise(cX, cZ)) / 2 + abs(cellular.GetNoise(cX, cZ)) * 2 + abs(os.GetNoise(cX, cZ)) * 4 + 10; y++)
|
2022-10-29 20:09:42 +02:00
|
|
|
{
|
2022-11-01 00:06:45 +01:00
|
|
|
blockManager.mapBlocks[bx][bz].addNode(y > 20 ? 1 : 2, 0, x, y, z);
|
2022-10-29 20:09:42 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-23 23:44:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 20:09:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2022-10-30 20:43:20 +01:00
|
|
|
for(int y = 0; y < 16; y++)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 20:43:20 +01:00
|
|
|
for(int x = 0; x < 16; x++)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-30 20:43:20 +01:00
|
|
|
for(int z = 0; z < 16; z++)
|
2022-10-22 17:03:43 +02:00
|
|
|
{
|
2022-10-29 20:09:42 +02:00
|
|
|
Position2D block = BlockUtilities::getBlockFromNodeCoordinates(x, z);
|
2022-10-30 20:43:20 +01:00
|
|
|
printf("\n|x: %i |y: %i | z: %i | id: %i", x, y, z, blockManager.getNodeAt(x, y, z));
|
2022-10-29 20:09:42 +02:00
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-29 20:09:42 +02:00
|
|
|
|
2022-10-30 20:43:20 +01:00
|
|
|
*/
|
2022-10-29 20:09:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-22 17:03:43 +02:00
|
|
|
|
2022-10-30 16:53:41 +01:00
|
|
|
updateTimer(0);
|
2022-10-23 23:44:58 +02:00
|
|
|
glutDisplayFunc(&display);
|
|
|
|
glutReshapeFunc(&reshape);
|
2022-10-22 17:03:43 +02:00
|
|
|
|
|
|
|
glutMainLoop();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|