terrain.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. *** :: Terrain ::
  3. ***
  4. *** - WIP -
  5. ***
  6. *** Accellerated terrain loaded from heightmap
  7. *** splits into chunks for faster rendering
  8. *** builds dynamic LODs into several index buffers
  9. ***
  10. **/
  11. #ifndef terrain_h
  12. #define terrain_h
  13. #include "cengine.h"
  14. #include "assets/cmesh.h"
  15. #define NUM_TERRAIN_SUBDIVISIONS 0
  16. #define NUM_TERRAIN_BUFFERS 7
  17. struct terrain_chunk {
  18. int id;
  19. int x, y, width, height;
  20. sphere bound;
  21. struct terrain_chunk* left;
  22. struct terrain_chunk* right;
  23. struct terrain_chunk* top;
  24. struct terrain_chunk* bottom;
  25. cmesh* colmesh;
  26. int num_verts;
  27. GLuint vertex_buffer;
  28. int num_indicies[NUM_TERRAIN_BUFFERS];
  29. GLuint index_buffers[NUM_TERRAIN_BUFFERS];
  30. };
  31. struct terrain_chunk;
  32. typedef struct terrain_chunk terrain_chunk;
  33. void terrain_chunk_delete(terrain_chunk* tc);
  34. typedef struct {
  35. int width;
  36. int height;
  37. float* heightmap;
  38. int chunk_width;
  39. int chunk_height;
  40. int num_chunks;
  41. int num_cols;
  42. int num_rows;
  43. terrain_chunk** chunks;
  44. } terrain;
  45. terrain* raw_load_file(char* filename);
  46. void raw_save_file(terrain* ter, char* filename);
  47. void terrain_delete(terrain* ter);
  48. terrain_chunk* terrain_get_chunk(terrain* ter, int x, int y);
  49. void terrain_reload_chunk(terrain* ter, int i);
  50. mat3 terrain_tbn(terrain* ter, vec2 position);
  51. mat3 terrain_axis(terrain* ter, vec2 position);
  52. float terrain_height(terrain* ter, vec2 position);
  53. vec3 terrain_normal(terrain* ter, vec2 position);
  54. #endif