KGLLib
simpleterrain.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KGLLIB_SIMPLETERRAIN_H
00019 #define KGLLIB_SIMPLETERRAIN_H
00020
00021
00022 #include "mesh.h"
00023
00024 #include <Eigen/Core>
00025
00026
00027 class QString;
00028
00029
00030 namespace KGLLib
00031 {
00032 class Batch;
00033
00034 class KGLLIB_EXTRAS_EXPORT SimpleTerrain : public Mesh
00035 {
00036 public:
00037 SimpleTerrain(const QString& imgfilename);
00038 virtual ~SimpleTerrain();
00039
00040 virtual void render();
00041
00042 void setHeightRange(float min, float max);
00043 void setTileSize(float size);
00044
00045 int width() const { return mWidth; }
00046 int height() const { return mHeight; }
00047 float tileSize() const { return mTileSize; }
00048 bool isValid() const;
00049
00050 protected:
00051 void addVertex(int x, int z, int index);
00052 void recalcNormalmap();
00053 void cookMesh(bool useIndices);
00054 inline float height(int x, int z) const { return mMinHeight + mHeightmap[x][z] * (mMaxHeight - mMinHeight); }
00055 Eigen::Vector3f cellNormal(int x1, int z1, int x2, int z2, int x3, int z3);
00056 void setDirty();
00057
00058 protected:
00059 class Chunk;
00060 float** mHeightmap;
00061 Eigen::Vector3f** mNormalmap;
00062 bool mDirty;
00063
00064 Eigen::Vector3f* mVertices;
00065 Eigen::Vector3f* mNormals;
00066 unsigned int* mIndices;
00067
00068 int mWidth;
00069 int mHeight;
00070
00071 float mMinHeight;
00072 float mMaxHeight;
00073 float mTileSize;
00074 };
00075
00076 }
00077
00078 #endif