Waterflow
Visualize water in terrain
src/voxel.h
00001 #ifndef VOXEL_H
00002 #define VOXEL_H
00003 
00004 #include <vector>
00005 #include <inttypes.h>
00006 
00007 #include "glm.hpp"
00008 #include "readData.h"
00009 #include "glm.hpp"
00010 
00014 
00015 struct voxel{
00016   bool filled;  
00017   float a;      
00018   float b;      
00019   int16_t x;    
00020   int16_t y;    
00021   int16_t z;    
00022 };
00023 
00036 struct neighs {
00037     voxel* voxs[27]; 
00038 };
00039 
00048 class Voxelgrid
00049 {
00050 private:
00051   std::vector<std::vector<std::vector<voxel*>*>*>* voxels; 
00052   DataHandler* datahandler; 
00053 
00054   std::vector<GLuint>* voxelPositions; 
00055   GLuint numVoxels; 
00056   GLuint voxelShader; 
00057   GLuint voxelBuffer;
00058   GLuint voxelVAO; 
00059 
00060   std::vector<GLint>* waterHeight; 
00061   GLuint width; 
00062   GLuint height; 
00063 
00064 
00065   GLfloat rehashTresh; 
00066 
00067 
00068   std::vector<voxel*>* hashTable; 
00069 
00070 
00076   int64_t hashFunc(int64_t x, int64_t y, int64_t z,int64_t inHashSize);
00077 
00078   int xoff[27]; 
00079   int yoff[27]; 
00080   int zoff[27]; 
00081 
00082 
00083 public:
00084 
00085   int64_t hashSize; 
00086 
00087   GLuint numInTable; 
00088   GLuint numCollisions; 
00089 
00104   Voxelgrid(DataHandler* handle,int64_t hashSize);
00105 
00106 
00108   ~Voxelgrid();
00109 
00124   void setVoxel(int16_t x, int16_t y, int16_t z, bool filled, float a, float b);
00125 
00136   voxel* getVoxel(int16_t x, int16_t y, int16_t z);
00137 
00143   void FloodFill(int x, int z, int height, bool fillDown = true);
00144 
00145 
00150   std::vector<GLuint> *getVoxelPositions();
00151 
00156   void initDraw();
00157 
00163   void updateVoxelrender();
00164 
00170   void drawVoxels(glm::mat4 projectionMatrix, glm::mat4 viewMatrix);
00171 
00175   void hashAdd(int16_t x, int16_t y, int16_t z,bool filled, float a, float b);
00180   voxel* hashGet(int16_t x, int16_t y, int16_t z);
00186   void rehash();
00187 
00190   bool isEqualPoint(voxel* vox,short int x, short int y,short int z);
00196   void hashInit();
00197 
00201   neighs* getNeighbourhood(int16_t x, int16_t y, int16_t z);
00202 
00207   neighs* getNeighbourhoodHash(int16_t x, int16_t y, int16_t z);
00208 
00209 
00215   void setHeight(int16_t x, int16_t y, int16_t z);
00216 
00221   GLint getHeight(int16_t x, int16_t z);
00222 
00230   std::vector<GLint>* getHeightMap();
00231 
00232 };
00233 
00234 #endif
 All Classes Files Functions Variables Enumerations