diff --git a/src/Application.cpp b/src/Application.cpp index 32e1e2a..2ea41d7 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -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); diff --git a/src/planet/Chunk.cpp b/src/planet/Chunk.cpp index 0a66d75..93f8675 100644 --- a/src/planet/Chunk.cpp +++ b/src/planet/Chunk.cpp @@ -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;idraw(camera); + } +} + +void Planet::tick(GLfloat dtime) +{ + for (int i = 0; i < 6; i++) + { + m_faces[i]->tick(dtime); + } } diff --git a/src/planet/Planet.h b/src/planet/Planet.h index 19b8bb7..534a131 100644 --- a/src/planet/Planet.h +++ b/src/planet/Planet.h @@ -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; diff --git a/src/planet/PlanetFace.cpp b/src/planet/PlanetFace.cpp index e7bfc12..5cb142e 100644 --- a/src/planet/PlanetFace.cpp +++ b/src/planet/PlanetFace.cpp @@ -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;idestroyChunk(); } + +void PlanetFace::draw(Camera* camera) +{ + for(int i=0;idraw(camera); +} + +void PlanetFace::tick(GLfloat dtime) +{ + for(int i=0;itick(dtime); +} diff --git a/src/planet/PlanetFace.h b/src/planet/PlanetFace.h index 406f8a9..a28ca31 100644 --- a/src/planet/PlanetFace.h +++ b/src/planet/PlanetFace.h @@ -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];