implemented loading of the heightmap from a png to unsigned int**
This commit is contained in:
parent
911c8ebfcc
commit
925eb62831
27
terrain.cc
27
terrain.cc
@ -5,3 +5,30 @@ 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 <string>
|
||||||
#include "texture.hh"
|
#include "texture.hh"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include "png.h"
|
||||||
|
//#include <winsock.h> //on windows
|
||||||
|
#include <netinet/in.h> //on Unix
|
||||||
|
|
||||||
class Terrain {
|
class Terrain {
|
||||||
public:
|
public:
|
||||||
@ -14,6 +19,7 @@ class Terrain {
|
|||||||
float friction;
|
float friction;
|
||||||
Texture texture;
|
Texture texture;
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
|
unsigned int** heightmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user