87 lines
3.0 KiB
C++
87 lines
3.0 KiB
C++
#ifndef TILE_H
|
|
#define TILE_H
|
|
#include <QOpenGLShaderProgram>
|
|
#include <QOpenGLBuffer>
|
|
#include <QOpenGLVertexArrayObject>
|
|
#include <QOpenGLTexture>
|
|
#include "vertex.h"
|
|
#include "terrain.h"
|
|
#include "tilevertexinfo.h"
|
|
#include <QVector>
|
|
#include "face.h"
|
|
class QSceneRenderer;
|
|
|
|
class Tile
|
|
{
|
|
public:
|
|
Tile();
|
|
void init(QSceneRenderer* s,int x, int y);
|
|
void paint(QMatrix4x4 p,QVector3D& cameraPosition,QVector3D& cameraUpDirection,QMatrix4x4& vMatrix, float time);
|
|
void buildVertices();
|
|
void buildNormals();
|
|
bool isInitialized() const { return m_initialized; }
|
|
bool normalsBuilt() const { return m_normalsBuilt; }
|
|
void ensureInitialized(QSceneRenderer* s, int x, int y);
|
|
void ensureNormalsBuilt();
|
|
void findFaces(std::vector<Face *> &vec, QVector2D s);
|
|
QVector2D getWorldPosition() const {
|
|
return QVector2D(m_x * (LOD_0_SIZE * 0.75f), m_y * (LOD_0_SIZE_Y * 2.0f) + (m_x % 2 == 0 ? 0.0f : LOD_0_SIZE_Y));
|
|
}
|
|
void addRiverEdge(int edge) { m_riverMask |= (1 << ((edge % 6 + 6) % 6)); }
|
|
void setRiverMask(unsigned char mask) { m_riverMask = mask; }
|
|
unsigned char getRiverMask() const { return m_riverMask; }
|
|
bool hasRiver() const { return m_riverMask != 0; }
|
|
static float getRiverDistance(QVector2D p, unsigned char mask);
|
|
protected:
|
|
void addTriangleVertices(int &cnt, QVector2D t1, QVector2D t2, QVector2D t3,int level, int hex, int l1);
|
|
void drawSubTriangleVertices(int &cnt, QVector2D t1, QVector2D t2, QVector2D t3, int hex, int l1, int l2);
|
|
void buildHeights();
|
|
|
|
QOpenGLBuffer m_heightsbuffer;
|
|
static QOpenGLBuffer m_vertex;
|
|
static QOpenGLVertexArrayObject m_object;
|
|
static QOpenGLShaderProgram *m_program;
|
|
QSceneRenderer *m_scene;
|
|
static int m_numVertex;
|
|
TileVertexInfo * m_tilevertices;
|
|
|
|
std::vector<Face> m_faces;
|
|
Face m_face[6];
|
|
|
|
int m_x;
|
|
int m_y;
|
|
|
|
float m_startpoint_x;
|
|
float m_startpoint_y;
|
|
bool m_initialized;
|
|
bool m_normalsBuilt;
|
|
unsigned char m_riverMask;
|
|
static Vertex * m_vertices;
|
|
static QOpenGLTexture * m_texture_grass;
|
|
static QOpenGLTexture * m_texture_border;
|
|
static QOpenGLTexture * m_texture_rock;
|
|
static QOpenGLTexture * m_texture_sand;
|
|
static QOpenGLTexture * m_texture_water;
|
|
static QOpenGLTexture * m_texture_snow;
|
|
static QOpenGLTexture * m_texture_typemap;
|
|
static QOpenGLTexture * m_texture_sahara;
|
|
static QOpenGLTexture * m_texture_tundra;
|
|
static QOpenGLTexture * m_texture_redsand;
|
|
static QOpenGLTexture * m_texture_redrock;
|
|
static QOpenGLTexture * m_texture_forest;
|
|
static QImage * m_image_grass;
|
|
static QImage * m_image_rock;
|
|
static QImage * m_image_border;
|
|
static QImage * m_image_sand;
|
|
static QImage * m_image_water;
|
|
static QImage * m_image_snow;
|
|
static QImage * m_image_typemap;
|
|
static QImage * m_image_sahara;
|
|
static QImage * m_image_tundra;
|
|
static QImage * m_image_redsand;
|
|
static QImage * m_image_redrock;
|
|
static QImage * m_image_forest;
|
|
};
|
|
|
|
#endif // TILE_H
|