From fa65d01b8b0b3163e34ab42350ebbce239a2b0e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Tue, 4 Nov 2014 19:40:35 +0100 Subject: [PATCH] implemented reading the heightmap from png --- terrain.cc | 29 ++++++++++++++++++++++++++++- terrain.hh | 4 ++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/terrain.cc b/terrain.cc index 9b11ed1..313d96c 100644 --- a/terrain.cc +++ b/terrain.cc @@ -1,7 +1,34 @@ #include "terrain.hh" -Terrain::Terrain() { +Terrain::Terrain(){ } Terrain::~Terrain() { } + + +void Terrain::load() { + std::ifstream terrain_png(this->filePath); + unsigned int width, height, rowNum, columnNum; + + terrain_png.seekg(16); //skip part of the header + terrain_png.read((char *)&width, 4); //read width + terrain_png.read((char *)&height, 4); //read height + width = ntohl(width); //convert from host to network byte order + height = ntohl(height); + + heightmap = new unsigned int*[height]; //initialize the heightmap + for(rowNum=0; rowNum #include "texture.hh" +#include +//#include //on Windows +#include //on Unix class Terrain { public: @@ -14,6 +17,7 @@ class Terrain { float friction; Texture texture; std::string filePath; + unsigned int** heightmap; //can be accessed like 'unsigned int[][]' }; #endif