implemented loading of the heightmap from a png to unsigned int**
This commit is contained in:
parent
911c8ebfcc
commit
925eb62831
29
terrain.cc
29
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);
|
||||
terrain_png.read((char *)&width, 4);
|
||||
terrain_png.read((char *)&height, 4);
|
||||
width = ntohl(width);
|
||||
height = ntohl(height);
|
||||
|
||||
heightmap = new unsigned int*[height];
|
||||
for(rowNum=0; rowNum<height; rowNum++){
|
||||
heightmap[columnNum] = new unsigned int[width];
|
||||
for(columnNum=0; columnNum<width; columnNum++){
|
||||
terrain_png.read((char *)&heightmap[columnNum][rowNum], 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Terrain::render() {
|
||||
}
|
||||
|
@ -3,6 +3,11 @@
|
||||
|
||||
#include <string>
|
||||
#include "texture.hh"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "png.h"
|
||||
//#include <winsock.h> //on windows
|
||||
#include <netinet/in.h> //on Unix
|
||||
|
||||
class Terrain {
|
||||
public:
|
||||
@ -14,6 +19,7 @@ class Terrain {
|
||||
float friction;
|
||||
Texture texture;
|
||||
std::string filePath;
|
||||
unsigned int** heightmap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user