mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
added slope image
This commit is contained in:
parent
58f3f8f322
commit
15dba6ef35
@ -292,10 +292,10 @@ get_elevation(double x, double y) {
|
|||||||
// accurate normals, please divide it by the
|
// accurate normals, please divide it by the
|
||||||
// terrain scale and normalize it again, like this:
|
// terrain scale and normalize it again, like this:
|
||||||
//
|
//
|
||||||
// LVector3f normal (terr.get_normal(mx, my, x, y));
|
// LVector3f normal (terr.get_normal(x, y));
|
||||||
// normal.set(normal.get_x() / terr.get_sx(),
|
// normal.set(normal.get_x() / root.get_sx(),
|
||||||
// normal.get_y() / terr.get_sy(),
|
// normal.get_y() / root.get_sy(),
|
||||||
// normal.get_z() / terr.get_sz());
|
// normal.get_z() / root.get_sz());
|
||||||
// normal.normalize();
|
// normal.normalize();
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
LVector3f GeoMipTerrain::
|
LVector3f GeoMipTerrain::
|
||||||
@ -316,6 +316,36 @@ get_normal(int x, int y) {
|
|||||||
return normal;
|
return normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: GeoMipTerrain::make_slope_image
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns a new grayscale image containing the slope
|
||||||
|
// angles. A pixel value of 1.0 will mean 90 degrees,
|
||||||
|
// meaning, horizontal, a pixel value of 0.0 will
|
||||||
|
// mean 0 degrees, or entirely vertical.
|
||||||
|
// The resulting image will have the same size as the
|
||||||
|
// heightfield image.
|
||||||
|
// The scale will be taken into respect -- meaning,
|
||||||
|
// if you change the terrain scale, the slope image
|
||||||
|
// will need to be regenerated in order to be correct.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
PNMImage GeoMipTerrain::
|
||||||
|
make_slope_image() {
|
||||||
|
PNMImage result (_xsize, _ysize);
|
||||||
|
result.make_grayscale();
|
||||||
|
for (int x = 0; x < _xsize; ++x) {
|
||||||
|
for (int y = 0; y < _ysize; ++y) {
|
||||||
|
LVector3f normal (get_normal(x, y));
|
||||||
|
normal.set(normal.get_x() / _root.get_sx(),
|
||||||
|
normal.get_y() / _root.get_sy(),
|
||||||
|
normal.get_z() / _root.get_sz());
|
||||||
|
normal.normalize();
|
||||||
|
result.set_gray(x, y, normal.angle_deg(LVector3f::up()) / 90.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::generate
|
// Function: GeoMipTerrain::generate
|
||||||
// Access: Published
|
// Access: Published
|
||||||
|
@ -105,6 +105,7 @@ PUBLISHED:
|
|||||||
unsigned short my);
|
unsigned short my);
|
||||||
INLINE LVecBase2f get_block_from_pos(double x, double y);
|
INLINE LVecBase2f get_block_from_pos(double x, double y);
|
||||||
|
|
||||||
|
PNMImage make_slope_image();
|
||||||
void generate();
|
void generate();
|
||||||
bool update();
|
bool update();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user