medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b23578fa5dc6714d34c1058fc3c2ca6817960a74
parent c68419f5f2694a8a280221fff6f295eee8935245
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Aug 30 21:22:53 +0200

Add terrain_height function

Diffstat:
heightmap.h | 3+--
terrain_manager.cc | 9+++++++++
terrain_manager.h | 1+
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/heightmap.h b/heightmap.h @@ -9,7 +9,7 @@ #include "intrinsics.h" class Heightmap { -private: +public: u8 * pixels; int w, h; @@ -19,7 +19,6 @@ private: GLuint ebo; GLuint vao; -public: ~Heightmap(); void load( const std::string & image, const int ox, const int oy, diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -208,3 +208,12 @@ void terrain_render( const TerrainManager * const tm, const glm::mat4 VP, const glUseProgram( 0 ); } + +float terrain_height( const TerrainManager * const tm, const float x, const float y ) { + const u32 tx = x / TILE_SIZE; + const u32 ty = y / TILE_SIZE; + + const Heightmap * const hm = &tm->tiles[ tx ][ ty ]; + + return hm->height( x - tx * TILE_SIZE, y - ty * TILE_SIZE ); +} diff --git a/terrain_manager.h b/terrain_manager.h @@ -37,5 +37,6 @@ void terrain_init( TerrainManager * const tm, const char * const tiles_dir ); void terrain_teleport( TerrainManager * const tm, const glm::vec3 position ); void terrain_update( TerrainManager * const tm, const glm::vec3 position ); void terrain_render( const TerrainManager * const tm, const glm::mat4 VP, const float sun_slope ); +float terrain_height( const TerrainManager * const tm, const float x, const float y ); #endif // _TERRAIN_MANAGER_H_