Fixed a bug in loading the heightmap and added comments
This commit is contained in:
parent
925eb62831
commit
5d2acc0e53
16
terrain.cc
16
terrain.cc
@ -11,17 +11,17 @@ void Terrain::load() {
|
|||||||
std::ifstream terrain_png(this->filePath);
|
std::ifstream terrain_png(this->filePath);
|
||||||
unsigned int width, height, rowNum, columnNum;
|
unsigned int width, height, rowNum, columnNum;
|
||||||
|
|
||||||
terrain_png.seekg(16);
|
terrain_png.seekg(16); //skip part of the header
|
||||||
terrain_png.read((char *)&width, 4);
|
terrain_png.read((char *)&width, 4); //read width
|
||||||
terrain_png.read((char *)&height, 4);
|
terrain_png.read((char *)&height, 4); //read height
|
||||||
width = ntohl(width);
|
width = ntohl(width); //convert from host to network byte order
|
||||||
height = ntohl(height);
|
height = ntohl(height);
|
||||||
|
|
||||||
heightmap = new unsigned int*[height];
|
heightmap = new unsigned int*[height]; //initialize the heightmap
|
||||||
for(rowNum=0; rowNum<height; rowNum++){
|
for(rowNum=0; rowNum<height; rowNum++){ //read in the heightmap
|
||||||
heightmap[columnNum] = new unsigned int[width];
|
heightmap[rowNum] = new unsigned int[width];
|
||||||
for(columnNum=0; columnNum<width; columnNum++){
|
for(columnNum=0; columnNum<width; columnNum++){
|
||||||
terrain_png.read((char *)&heightmap[columnNum][rowNum], 1);
|
terrain_png.read((char *)&heightmap[rowNum][columnNum], 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "texture.hh"
|
#include "texture.hh"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
//#include <winsock.h> //on Windows
|
||||||
#include "png.h"
|
|
||||||
//#include <winsock.h> //on windows
|
|
||||||
#include <netinet/in.h> //on Unix
|
#include <netinet/in.h> //on Unix
|
||||||
|
|
||||||
class Terrain {
|
class Terrain {
|
||||||
@ -19,7 +17,7 @@ class Terrain {
|
|||||||
float friction;
|
float friction;
|
||||||
Texture texture;
|
Texture texture;
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
unsigned int** heightmap;
|
unsigned int** heightmap; //can be accessed like 'unsigned int[][]'
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user