I \/really\/ don't know how to do it..
This commit is contained in:
parent
9d514f2335
commit
ee0abf4d5b
|
@ -18,6 +18,8 @@
|
|||
#include "util/Log.h"
|
||||
#include "Shader.h"
|
||||
|
||||
#include "planet/Planet.h"
|
||||
|
||||
Application::Application() : m_width(1080), m_height(720)
|
||||
{
|
||||
|
||||
|
@ -222,6 +224,8 @@ void Application::run()
|
|||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
Planet* pl = new Planet(glm::vec3(0.0f,0.0f,0.0f), 20);
|
||||
|
||||
// END TEST CODE
|
||||
|
||||
while(m_run)
|
||||
|
@ -251,7 +255,9 @@ void Application::run()
|
|||
// END TEST CODE
|
||||
|
||||
update(deltaTime);
|
||||
pl->tick(deltaTime);
|
||||
render();
|
||||
pl->draw(m_camera);
|
||||
|
||||
// Update window with OpenGL rendering
|
||||
SDL_GL_SwapWindow(m_window);
|
||||
|
|
|
@ -10,12 +10,26 @@ Chunk::Chunk(Planet* planet, class PlanetFace* face, int x, int y, int z) :
|
|||
m_dirty(false),
|
||||
m_active(true)
|
||||
{
|
||||
|
||||
// Create cells
|
||||
for(int i=0;i<CHUNK_N;i++)
|
||||
{
|
||||
for(int j=0;j<CHUNK_N;j++)
|
||||
{
|
||||
for(int k=0;k<CHUNK_N;k++)
|
||||
{
|
||||
m_cells[i][j][k] = new Cell();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Chunk::~Chunk()
|
||||
{
|
||||
|
||||
for(int i=0;i<CHUNK_N;i++)
|
||||
for(int j=0;j<CHUNK_N;j++)
|
||||
for(int k=0;k<CHUNK_N;k++)
|
||||
if(m_cells[i][j][k])
|
||||
delete m_cells[i][j][k];
|
||||
}
|
||||
|
||||
void Chunk::destroyChunk()
|
||||
|
@ -23,3 +37,13 @@ void Chunk::destroyChunk()
|
|||
m_active = false;
|
||||
delete this;
|
||||
}
|
||||
|
||||
void Chunk::tick(GLfloat dtime)
|
||||
{
|
||||
if (!m_active) return;
|
||||
}
|
||||
|
||||
void Chunk::draw(Camera* camera)
|
||||
{
|
||||
if (!m_active) return;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,16 @@
|
|||
|
||||
#include "util/Common.h"
|
||||
#include "planet/Planet.h"
|
||||
#include "Camera.h"
|
||||
|
||||
#define CHUNK_N 32
|
||||
|
||||
struct Cell
|
||||
{
|
||||
glm::vec3 position;
|
||||
GLuint internalId;
|
||||
};
|
||||
|
||||
class Chunk
|
||||
{
|
||||
public:
|
||||
|
@ -13,6 +20,9 @@ class Chunk
|
|||
~Chunk();
|
||||
|
||||
void destroyChunk();
|
||||
|
||||
void tick(GLfloat dtime);
|
||||
void draw(Camera* camera);
|
||||
private:
|
||||
Planet* m_planet;
|
||||
class PlanetFace* m_planetFace;
|
||||
|
@ -23,5 +33,7 @@ class Chunk
|
|||
int m_cx, m_cy, m_cz;
|
||||
|
||||
GLuint m_vao, m_vbo;
|
||||
|
||||
Cell* m_cells[CHUNK_N][CHUNK_N][CHUNK_N];
|
||||
};
|
||||
#endif // __CHUNK_H__
|
||||
|
|
|
@ -3,10 +3,32 @@
|
|||
|
||||
Planet::Planet(glm::vec3 position, float radius) : m_position(position), m_radius(radius)
|
||||
{
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_faces[i] = new PlanetFace(this, i);
|
||||
}
|
||||
}
|
||||
|
||||
Planet::~Planet()
|
||||
{
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
delete m_faces[i];
|
||||
}
|
||||
}
|
||||
|
||||
void Planet::draw(Camera* camera)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_faces[i]->draw(camera);
|
||||
}
|
||||
}
|
||||
|
||||
void Planet::tick(GLfloat dtime)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
m_faces[i]->tick(dtime);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "util/Common.h"
|
||||
#include "Shader.h"
|
||||
#include "Camera.h"
|
||||
|
||||
class PlanetFace;
|
||||
class Planet
|
||||
|
@ -13,6 +14,9 @@ class Planet
|
|||
|
||||
inline void setLightDirection(glm::vec3 lightDir) { m_lightDir = lightDir; }
|
||||
inline glm::vec3 getLightDirection() const { return m_lightDir; }
|
||||
|
||||
void tick(GLfloat dtime);
|
||||
void draw(Camera* camera);
|
||||
private:
|
||||
glm::vec3 m_position;
|
||||
float m_radius;
|
||||
|
|
|
@ -4,6 +4,29 @@
|
|||
PlanetFace::PlanetFace(Planet* planet, const unsigned int face) :
|
||||
m_planet(planet), m_face(face)
|
||||
{
|
||||
// Set face normal depending on face
|
||||
switch (m_face) {
|
||||
case Face::FACE_BOTTOM:
|
||||
m_normal = glm::vec3(0.0f, -1.0f, 0.0f);
|
||||
break;
|
||||
case Face::FACE_TOP:
|
||||
m_normal = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
break;
|
||||
case Face::FACE_LEFT:
|
||||
m_normal = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||
break;
|
||||
case Face::FACE_RIGHT:
|
||||
m_normal = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
break;
|
||||
case Face::FACE_FRONT:
|
||||
m_normal = glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
break;
|
||||
case Face::FACE_BACK:
|
||||
m_normal = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
break;
|
||||
}
|
||||
|
||||
// Create chunks
|
||||
for(int i=0;i<CHUNKS_W;i++)
|
||||
{
|
||||
for(int j=0;j<CHUNKS_H;j++)
|
||||
|
@ -18,9 +41,26 @@ PlanetFace::PlanetFace(Planet* planet, const unsigned int face) :
|
|||
|
||||
PlanetFace::~PlanetFace()
|
||||
{
|
||||
// Delete chunks
|
||||
for(int i=0;i<CHUNKS_W;i++)
|
||||
for(int j=0;j<CHUNKS_H;j++)
|
||||
for(int k=0;k<CHUNKS_D;k++)
|
||||
if(m_chunks[i][j][k])
|
||||
m_chunks[i][j][k]->destroyChunk();
|
||||
}
|
||||
|
||||
void PlanetFace::draw(Camera* camera)
|
||||
{
|
||||
for(int i=0;i<CHUNKS_W;i++)
|
||||
for(int j=0;j<CHUNKS_H;j++)
|
||||
for(int k=0;k<CHUNKS_D;k++)
|
||||
m_chunks[i][j][k]->draw(camera);
|
||||
}
|
||||
|
||||
void PlanetFace::tick(GLfloat dtime)
|
||||
{
|
||||
for(int i=0;i<CHUNKS_W;i++)
|
||||
for(int j=0;j<CHUNKS_H;j++)
|
||||
for(int k=0;k<CHUNKS_D;k++)
|
||||
m_chunks[i][j][k]->tick(dtime);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "util/Common.h"
|
||||
#include "planet/Chunk.h"
|
||||
#include "Shader.h"
|
||||
#include "Camera.h"
|
||||
|
||||
#define CHUNKS_W 1
|
||||
#define CHUNKS_D CHUNKS_W
|
||||
|
@ -21,10 +22,16 @@ class PlanetFace
|
|||
public:
|
||||
PlanetFace(Planet* planet, const unsigned int face = Face::FACE_BOTTOM);
|
||||
~PlanetFace();
|
||||
|
||||
void tick(GLfloat dtime);
|
||||
void draw(Camera* camera);
|
||||
private:
|
||||
Planet* m_planet;
|
||||
unsigned int m_face;
|
||||
|
||||
glm::vec3 m_normal;
|
||||
glm::vec3 m_pos;
|
||||
|
||||
int x, z;
|
||||
|
||||
Chunk* m_chunks[CHUNKS_W][CHUNKS_H][CHUNKS_D];
|
||||
|
|
Loading…
Reference in New Issue