📄 heightmap.cpp
字号:
//////////////////////////////////////////////////////////////////////
// heightmap.cpp by Tobias Franke (webmaster@cyberhead.de) 2001 //
//////////////////////////////////////////////////////////////////////
#include "heightmap.h"
heightmap::heightmap(void)
{
hmap = 0;
width=height=0;
}
bool heightmap::create(int x, int y)
{
hmap = new float[x*y];
if (hmap)
{
width=x; height=y;
return true;
}
else
return false;
}
bool heightmap::load(char *filename)
{
bitmap map;
if (!map.load (filename)) return false;
create (map.getwidth(), map.getheight());
if (hmap)
{
for (int z=0; z<map.getheight(); z++)
for (int x=0; x<map.getwidth(); x++)
{
hmap[x+(z*width)]=map.data[(x+(z*map.getwidth()))*3 + 1]; //Check for green value
}
return true;
}
else return false;
}
bool heightmap::save(char *filename)
{
unsigned char r, g, b;
bitmap map;
if (!map.create (width, height)) return false;
if (hmap)
{
for (int z=0; z<height; z++)
for (int x=0; x<width; x++)
{
r=g=b=(unsigned)hmap[x+(z*width)];
map.setcolor(x, z, r, g, b);
}
if (!map.save (filename)) return false;
return true;
}
else return false;
}
void heightmap::reset(void)
{
if (hmap)
{
delete hmap;
width=height=0;
}
}
heightmap::~heightmap(void)
{
if (hmap)
delete hmap;
hmap = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -