Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / 3d / height_map.cpp
blob4236cd15eca1a7f08def3bbfbca16b7f73ab9885
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
19 #include "nel/3d/height_map.h"
22 using namespace NLMISC;
24 #ifdef DEBUG_NEW
25 #define new DEBUG_NEW
26 #endif
28 namespace NL3D
32 // ***************************************************************************
33 void CHeightMap::resize(uint w, uint h)
35 _Width= w;
36 _Height= h;
37 Heights.resize(w*h);
41 // ***************************************************************************
42 void CHeightMap::buildFromBitmap(const NLMISC::CBitmap &bitmap0)
44 // copy bitmap.
45 CBitmap bitmap= bitmap0;
46 // convert to luminance.
47 bitmap.convertToType(CBitmap::Luminance);
49 // resize array.
50 uint w, h;
51 w= bitmap.getWidth();
52 h= bitmap.getHeight();
53 resize(w,h);
55 // get luminance image.
56 CObjectVector<uint8> &array= bitmap.getPixels();
57 // invert the image in Y.
58 for(uint y=0;y<h;y++)
60 for(uint x=0;x<w;x++)
62 uint8 v= array[(h-1-y)*w+x];
63 Heights[y*w+x]= v;
69 // ***************************************************************************
70 float CHeightMap::getZ(uint x, uint y) const
72 nlassert(x<_Width && y<_Height);
73 return Heights[y*_Width+x]*MaxZ/255;
78 } // NL3D