From 15dba6ef35cde494411c7d58f9e19f0104b39707 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 11 Oct 2008 10:00:25 +0000 Subject: [PATCH] added slope image --- panda/src/grutil/geoMipTerrain.cxx | 38 ++++++++++++++++++++++++++---- panda/src/grutil/geoMipTerrain.h | 1 + 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/panda/src/grutil/geoMipTerrain.cxx b/panda/src/grutil/geoMipTerrain.cxx index 25c083d4b1..6264daa449 100644 --- a/panda/src/grutil/geoMipTerrain.cxx +++ b/panda/src/grutil/geoMipTerrain.cxx @@ -292,10 +292,10 @@ get_elevation(double x, double y) { // accurate normals, please divide it by the // terrain scale and normalize it again, like this: // -// LVector3f normal (terr.get_normal(mx, my, x, y)); -// normal.set(normal.get_x() / terr.get_sx(), -// normal.get_y() / terr.get_sy(), -// normal.get_z() / terr.get_sz()); +// LVector3f normal (terr.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(); //////////////////////////////////////////////////////////////////// LVector3f GeoMipTerrain:: @@ -316,6 +316,36 @@ get_normal(int x, int y) { 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 // Access: Published diff --git a/panda/src/grutil/geoMipTerrain.h b/panda/src/grutil/geoMipTerrain.h index 97a715f844..3b92174dfd 100644 --- a/panda/src/grutil/geoMipTerrain.h +++ b/panda/src/grutil/geoMipTerrain.h @@ -105,6 +105,7 @@ PUBLISHED: unsigned short my); INLINE LVecBase2f get_block_from_pos(double x, double y); + PNMImage make_slope_image(); void generate(); bool update();