mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Integrate changes into 1.5 branch so I can tag it for 1.5.4
This commit is contained in:
parent
6bd9856ff2
commit
4b2ca15c43
@ -1,6 +1,6 @@
|
|||||||
// Filename: geoMipTerrain.I
|
// Filename: geoMipTerrain.I
|
||||||
// Created by: pro-rsoft (29jun07)
|
// Created by: pro-rsoft (29jun07)
|
||||||
// Last updated by: pro-rsoft (24sep08)
|
// Last updated by: pro-rsoft (03mar08)
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
@ -13,8 +13,6 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "config_grutil.h"
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::Constructor
|
// Function: GeoMipTerrain::Constructor
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -26,13 +24,9 @@ GeoMipTerrain(const string &name) {
|
|||||||
_root_flattened = false;
|
_root_flattened = false;
|
||||||
_xsize = 0;
|
_xsize = 0;
|
||||||
_ysize = 0;
|
_ysize = 0;
|
||||||
_block_size = 16;
|
|
||||||
_max_level = 4; // Always log(_block_size) / log(2.0)
|
|
||||||
_min_level = 0;
|
_min_level = 0;
|
||||||
|
_block_size = 16;
|
||||||
_factor = 100.0;
|
_factor = 100.0;
|
||||||
_near = 16.0;
|
|
||||||
_far = 128.0;
|
|
||||||
_use_near_far = false;
|
|
||||||
_has_color_map = false;
|
_has_color_map = false;
|
||||||
PT(PandaNode) tmpnode = new PandaNode("tmp_focal");
|
PT(PandaNode) tmpnode = new PandaNode("tmp_focal");
|
||||||
_auto_flatten = AFM_off;
|
_auto_flatten = AFM_off;
|
||||||
@ -64,7 +58,6 @@ INLINE PNMImage &GeoMipTerrain::
|
|||||||
heightfield() {
|
heightfield() {
|
||||||
return _heightfield;
|
return _heightfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::color_map
|
// Function: GeoMipTerrain::color_map
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -76,7 +69,6 @@ INLINE PNMImage &GeoMipTerrain::
|
|||||||
color_map() {
|
color_map() {
|
||||||
return _color_map;
|
return _color_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::set_bruteforce
|
// Function: GeoMipTerrain::set_bruteforce
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -93,7 +85,6 @@ set_bruteforce(bool bf) {
|
|||||||
}
|
}
|
||||||
_bruteforce = bf;
|
_bruteforce = bf;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::get_bruteforce
|
// Function: GeoMipTerrain::get_bruteforce
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -105,7 +96,6 @@ INLINE bool GeoMipTerrain::
|
|||||||
get_bruteforce() {
|
get_bruteforce() {
|
||||||
return _bruteforce;
|
return _bruteforce;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::set_auto_flatten
|
// Function: GeoMipTerrain::set_auto_flatten
|
||||||
// Access: Private
|
// Access: Private
|
||||||
@ -113,12 +103,12 @@ get_bruteforce() {
|
|||||||
// flatten_light, flatten_medium, or flatten_strong)
|
// flatten_light, flatten_medium, or flatten_strong)
|
||||||
// after each update. This only affects future
|
// after each update. This only affects future
|
||||||
// updates, it doesn't flatten the current terrain.
|
// updates, it doesn't flatten the current terrain.
|
||||||
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GeoMipTerrain::
|
INLINE void GeoMipTerrain::
|
||||||
set_auto_flatten(int mode) {
|
set_auto_flatten(int mode) {
|
||||||
_auto_flatten = mode;
|
_auto_flatten = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::set_focal_point
|
// Function: GeoMipTerrain::set_focal_point
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -163,7 +153,6 @@ set_focal_point(NodePath fp) {
|
|||||||
_focal_point = fp;
|
_focal_point = fp;
|
||||||
_focal_is_temporary = false;
|
_focal_is_temporary = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::get_focal_point
|
// Function: GeoMipTerrain::get_focal_point
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -204,7 +193,6 @@ INLINE void GeoMipTerrain::
|
|||||||
set_min_level(unsigned short minlevel) {
|
set_min_level(unsigned short minlevel) {
|
||||||
_min_level = minlevel;
|
_min_level = minlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::get_min_level
|
// Function: GeoMipTerrain::get_min_level
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -217,19 +205,6 @@ INLINE unsigned short GeoMipTerrain::
|
|||||||
get_min_level() {
|
get_min_level() {
|
||||||
return _min_level;
|
return _min_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: GeoMipTerrain::get_max_level
|
|
||||||
// Access: Published
|
|
||||||
// Description: Returns the highest level possible for this block
|
|
||||||
// size. When a block is at this level, it will be
|
|
||||||
// the worst quality possible.
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE unsigned short GeoMipTerrain::
|
|
||||||
get_max_level() {
|
|
||||||
return _max_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::get_block_size
|
// Function: GeoMipTerrain::get_block_size
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -239,7 +214,6 @@ INLINE unsigned short GeoMipTerrain::
|
|||||||
get_block_size() {
|
get_block_size() {
|
||||||
return _block_size;
|
return _block_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::set_block_size
|
// Function: GeoMipTerrain::set_block_size
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -265,7 +239,6 @@ set_block_size(unsigned short newbs) {
|
|||||||
_max_level = (unsigned short) (log((double) _block_size) / log(2.0));
|
_max_level = (unsigned short) (log((double) _block_size) / log(2.0));
|
||||||
_is_dirty = true;
|
_is_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::is_dirty
|
// Function: GeoMipTerrain::is_dirty
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -280,12 +253,10 @@ INLINE bool GeoMipTerrain::
|
|||||||
is_dirty() {
|
is_dirty() {
|
||||||
return _is_dirty;
|
return _is_dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::set_factor
|
// Function: GeoMipTerrain::set_factor
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: DEPRECATED method. Use set_near/far instead.
|
// Description: Sets the quality factor at which blocks must be
|
||||||
// Sets the quality factor at which blocks must be
|
|
||||||
// generated. The higher this level, the better
|
// generated. The higher this level, the better
|
||||||
// quality the terrain will be, but more expensive
|
// quality the terrain will be, but more expensive
|
||||||
// to render. A value of 0 makes the terrain the
|
// to render. A value of 0 makes the terrain the
|
||||||
@ -294,49 +265,22 @@ is_dirty() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GeoMipTerrain::
|
INLINE void GeoMipTerrain::
|
||||||
set_factor(float factor) {
|
set_factor(float factor) {
|
||||||
grutil_cat.debug() << "Using deprecated method set_factor, use set_near and set_far instead!\n";
|
|
||||||
_use_near_far = false;
|
|
||||||
_factor = factor;
|
_factor = factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::set_near_far
|
// Function: GeoMipTerrain::get_factor
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Sets the near and far LOD distances in one call.
|
// Description: Gets the quality factor at which blocks must be
|
||||||
|
// generated. The higher this level, the better
|
||||||
|
// quality the terrain will be, but more expensive
|
||||||
|
// to render. A value of 0 makes the terrain the
|
||||||
|
// lowest quality possible, depending on blocksize.
|
||||||
|
// The default value is 100.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE void GeoMipTerrain::
|
INLINE float GeoMipTerrain::
|
||||||
set_near_far(double input_near, double input_far) {
|
get_factor() {
|
||||||
_use_near_far = true;
|
return _factor;
|
||||||
_near = input_near;
|
|
||||||
_far = input_far;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: GeoMipTerrain::set_near
|
|
||||||
// Access: Published
|
|
||||||
// Description: Sets the near LOD distance, at which the terrain
|
|
||||||
// will be rendered at highest quality.
|
|
||||||
// This distance is in the terrain's coordinate space!
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void GeoMipTerrain::
|
|
||||||
set_near(double input_near) {
|
|
||||||
_use_near_far = true;
|
|
||||||
_near = input_near;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: GeoMipTerrain::set_far
|
|
||||||
// Access: Published
|
|
||||||
// Description: Sets the far LOD distance, at which the terrain
|
|
||||||
// will be rendered at lowest quality.
|
|
||||||
// This distance is in the terrain's coordinate space!
|
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
INLINE void GeoMipTerrain::
|
|
||||||
set_far(double input_far) {
|
|
||||||
_use_near_far = true;
|
|
||||||
_far = input_far;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::get_block_node_path
|
// Function: GeoMipTerrain::get_block_node_path
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -390,25 +334,13 @@ lod_decide(unsigned short mx, unsigned short my) {
|
|||||||
cx = (cx * _block_size + _block_size / 2) * _root.get_sx();
|
cx = (cx * _block_size + _block_size / 2) * _root.get_sx();
|
||||||
cy = (cy * _block_size + _block_size / 2) * _root.get_sy();
|
cy = (cy * _block_size + _block_size / 2) * _root.get_sy();
|
||||||
float d;
|
float d;
|
||||||
if (_use_near_far) {
|
if (_factor > 0.0) {
|
||||||
d = sqrt(pow(_focal_point.get_x(_root) - cx, 2) +
|
d = sqrt(pow(_focal_point.get_x(_root) - cx, 2) +
|
||||||
pow(_focal_point.get_y(_root) - cy, 2));
|
pow(_focal_point.get_y(_root) - cy, 2)) / _factor;
|
||||||
if (d < _near) {
|
|
||||||
return 0;
|
|
||||||
} else if (d > _far) {
|
|
||||||
return _max_level;
|
|
||||||
} else {
|
|
||||||
return (d - _near) / (_far - _near) * _max_level * (1.0 - (_min_level / _max_level)) + _min_level;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (_factor > 0.0) {
|
d = log((double) _block_size) / log(2.0);
|
||||||
d = sqrt(pow(_focal_point.get_x(_root) - cx, 2) +
|
|
||||||
pow(_focal_point.get_y(_root) - cy, 2)) / _factor;
|
|
||||||
} else {
|
|
||||||
d = _max_level;
|
|
||||||
}
|
|
||||||
return short(floor(d));
|
|
||||||
}
|
}
|
||||||
|
return short(floor(d));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -473,8 +405,11 @@ set_heightfield(const PNMImage &image) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
INLINE bool GeoMipTerrain::
|
INLINE bool GeoMipTerrain::
|
||||||
set_heightfield(const string &path) {
|
set_heightfield(const Texture *tex) {
|
||||||
return set_heightfield(Filename(path));
|
grutil_cat.warning() << "Setting a texture as heightfield image is deprecated!\n";
|
||||||
|
PNMImage image;
|
||||||
|
tex->store(image);
|
||||||
|
return set_heightfield(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -508,11 +443,6 @@ set_color_map(const Texture *tex) {
|
|||||||
_is_dirty = true;
|
_is_dirty = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
INLINE bool GeoMipTerrain::
|
|
||||||
set_color_map(const string &path) {
|
|
||||||
return set_heightfield(Filename(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::has_color_map
|
// Function: GeoMipTerrain::has_color_map
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -522,7 +452,6 @@ INLINE bool GeoMipTerrain::
|
|||||||
has_color_map() {
|
has_color_map() {
|
||||||
return _has_color_map;
|
return _has_color_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::clear_color_map
|
// Function: GeoMipTerrain::clear_color_map
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -535,7 +464,6 @@ clear_color_map() {
|
|||||||
_has_color_map = false;
|
_has_color_map = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::get_pixel_value
|
// Function: GeoMipTerrain::get_pixel_value
|
||||||
// Access: Private
|
// Access: Private
|
||||||
@ -547,13 +475,11 @@ INLINE double GeoMipTerrain::
|
|||||||
get_pixel_value(int x, int y) {
|
get_pixel_value(int x, int y) {
|
||||||
x = max(min(x,int(_xsize-1)),0);
|
x = max(min(x,int(_xsize-1)),0);
|
||||||
y = max(min(y,int(_ysize-1)),0);
|
y = max(min(y,int(_ysize-1)),0);
|
||||||
if (_heightfield.is_grayscale()) {
|
return double(_heightfield.get_bright(int(x),int(y)));
|
||||||
return double(_heightfield.get_bright(x, y));
|
/* return double(_heightfield.get_red_val(int(x),int(y))
|
||||||
} else {
|
+ _heightfield.get_green_val(int(x),int(y)) * 256
|
||||||
return double(_heightfield.get_red(x, y))
|
+ _heightfield.get_blue_val(int(x),int(y)) * 65536) / 16777215.0;
|
||||||
+ double(_heightfield.get_green(x, y)) / 256.0
|
*/
|
||||||
+ double(_heightfield.get_blue(x, y)) / 65536.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
INLINE double GeoMipTerrain::
|
INLINE double GeoMipTerrain::
|
||||||
get_pixel_value(unsigned short mx, unsigned short my, int x, int y) {
|
get_pixel_value(unsigned short mx, unsigned short my, int x, int y) {
|
||||||
@ -619,7 +545,6 @@ INLINE bool GeoMipTerrain::
|
|||||||
is_power_of_two(unsigned int i) {
|
is_power_of_two(unsigned int i) {
|
||||||
return !((i - 1) & i);
|
return !((i - 1) & i);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::f_part
|
// Function: GeoMipTerrain::f_part
|
||||||
// Access: Private
|
// Access: Private
|
||||||
@ -634,7 +559,6 @@ INLINE double GeoMipTerrain::
|
|||||||
f_part(double i) {
|
f_part(double i) {
|
||||||
return i - floor(i);
|
return i - floor(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: GeoMipTerrain::sfav
|
// Function: GeoMipTerrain::sfav
|
||||||
// Access: Private
|
// Access: Private
|
||||||
|
Loading…
x
Reference in New Issue
Block a user