voxspatium/src/planet/Chunk.h

83 lines
1.6 KiB
C++

#ifndef __CHUNK_H__
#define __CHUNK_H__
#include "util/Common.h"
#include "planet/Planet.h"
#include "Camera.h"
#define CHUNK_SIZE 16
struct Vertex
{
glm::vec3 position;
glm::vec3 normal;
glm::vec2 uv;
};
struct Cell
{
GLuint internalId;
bool isSolid()
{
return true;
}
};
enum CellFace {
CELL_FACE_BOTTOM, CELL_FACE_TOP,
CELL_FACE_LEFT, CELL_FACE_RIGHT,
CELL_FACE_FRONT, CELL_FACE_BACK
};
class Chunk
{
public:
Chunk(Planet* planet, class PlanetFace* face, int x, int y, int z);
~Chunk();
void unload();
void load();
void generate();
void rebuildMesh();
inline const glm::vec3 getPosition() const { return glm::vec3(m_cx, m_cy, m_cz); }
const glm::vec3 getAbsolutePosition();
inline int getX() const { return m_cx; }
inline int getY() const { return m_cy; }
inline int getZ() const { return m_cz; }
inline bool isLoaded() const { return m_active; }
inline bool isRedrawRequired() const { return m_dirty; }
inline bool isGenerated() const { return m_generated; }
inline bool shouldRender() const { return !m_emptyChunk && m_active && m_generated; }
inline glm::mat4 getModelMatrix() const { return m_model; }
bool isDetailedEnough(Camera* camera);
void draw(Camera* camera, Shader* shader);
void updateFlags();
private:
void formFace(std::vector<Vertex> &vertices, const glm::vec3 &position, CellFace face);
void deleteBuffers();
Planet* m_planet;
class PlanetFace* m_planetFace;
glm::mat4 m_model;
bool m_dirty;
bool m_active;
bool m_generated;
bool m_emptyChunk;
int m_cx, m_cy, m_cz;
GLuint m_vao, m_vbo;
Cell*** m_cells;
std::vector<Vertex> m_vertices;
};
#endif // __CHUNK_H__