00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GEOMIPTERRAIN_H
00016 #define GEOMIPTERRAIN_H
00017
00018 #include "pandabase.h"
00019
00020 #include "luse.h"
00021 #include "pandaNode.h"
00022 #include "pointerTo.h"
00023
00024 #include "pnmImage.h"
00025 #include "nodePath.h"
00026
00027 #include "texture.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class EXPCL_PANDA_GRUTIL GeoMipTerrain : public TypedObject {
00041 PUBLISHED:
00042 INLINE GeoMipTerrain(const string &name);
00043 INLINE ~GeoMipTerrain();
00044
00045 INLINE PNMImage &heightfield();
00046 bool set_heightfield(const Filename &filename, PNMFileType *type = NULL);
00047 INLINE bool set_heightfield(const PNMImage &image);
00048 INLINE bool set_heightfield(const string &path);
00049 INLINE PNMImage &color_map();
00050 INLINE bool set_color_map(const Filename &filename,
00051 PNMFileType *type = NULL);
00052 INLINE bool set_color_map(const PNMImage &image);
00053 INLINE bool set_color_map(const Texture *image);
00054 INLINE bool set_color_map(const string &path);
00055 INLINE bool has_color_map() const;
00056 INLINE void clear_color_map();
00057 void calc_ambient_occlusion(PN_stdfloat radius = 32, PN_stdfloat contrast = 2.0f, PN_stdfloat brightness = 0.75f);
00058 double get_elevation(double x, double y);
00059 LVector3 get_normal(int x, int y);
00060 INLINE LVector3 get_normal(unsigned short mx, unsigned short my,
00061 int x,int y);
00062 INLINE void set_bruteforce(bool bf);
00063 INLINE bool get_bruteforce();
00064
00065
00066
00067 enum AutoFlattenMode {
00068
00069 AFM_off = 0,
00070
00071 AFM_light = 1,
00072
00073 AFM_medium = 2,
00074
00075 AFM_strong = 3,
00076 };
00077
00078 INLINE void set_auto_flatten(int mode);
00079
00080
00081
00082
00083
00084 INLINE void set_focal_point(const LPoint2d &fp);
00085 INLINE void set_focal_point(const LPoint2f &fp);
00086 INLINE void set_focal_point(const LPoint3d &fp);
00087 INLINE void set_focal_point(const LPoint3f &fp);
00088 INLINE void set_focal_point(double x, double y);
00089 INLINE void set_focal_point(NodePath fnp);
00090 INLINE NodePath get_focal_point() const;
00091 INLINE NodePath get_root() const;
00092
00093 INLINE void set_block_size(unsigned short newbs);
00094 INLINE unsigned short get_block_size();
00095 INLINE unsigned short get_max_level();
00096 INLINE void set_min_level(unsigned short minlevel);
00097 INLINE unsigned short get_min_level();
00098 INLINE bool is_dirty();
00099 INLINE void set_factor(PN_stdfloat factor);
00100 INLINE void set_near_far(double input_near, double input_far);
00101 INLINE void set_near(double input_near);
00102 INLINE void set_far(double input_far);
00103 INLINE const NodePath get_block_node_path(unsigned short mx,
00104 unsigned short my);
00105 INLINE LVecBase2 get_block_from_pos(double x, double y);
00106 INLINE void set_border_stitching(bool stitching);
00107 INLINE bool get_border_stitching();
00108 INLINE double get_far();
00109 INLINE double get_near();
00110 INLINE int get_flatten_mode();
00111
00112 PNMImage make_slope_image();
00113 void generate();
00114 bool update();
00115
00116 private:
00117
00118 PT(GeomNode) generate_block(unsigned short mx, unsigned short my, unsigned short level);
00119 bool update_block(unsigned short mx, unsigned short my,
00120 signed short level = -1, bool forced = false);
00121 void calc_levels();
00122 void auto_flatten();
00123 bool root_flattened();
00124
00125 INLINE bool is_power_of_two(unsigned int i);
00126 INLINE float f_part(float i);
00127 INLINE double f_part(double i);
00128 INLINE int sfav(int n, int powlevel, int mypowlevel);
00129 INLINE double get_pixel_value(int x, int y);
00130 INLINE double get_pixel_value(unsigned short mx, unsigned short my, int x, int y);
00131 INLINE unsigned short lod_decide(unsigned short mx, unsigned short my);
00132 unsigned short get_neighbor_level(unsigned short mx, unsigned short my, short dmx, short dmy);
00133
00134 NodePath _root;
00135 int _auto_flatten;
00136 bool _root_flattened;
00137 PNMImage _heightfield;
00138 PNMImage _color_map;
00139 bool _is_dirty;
00140 bool _has_color_map;
00141 unsigned int _xsize;
00142 unsigned int _ysize;
00143 PN_stdfloat _factor;
00144 double _near;
00145 double _far;
00146 bool _use_near_far;
00147 unsigned short _block_size;
00148 unsigned short _max_level;
00149 bool _bruteforce;
00150 NodePath _focal_point;
00151 bool _focal_is_temporary;
00152 unsigned short _min_level;
00153 bool _stitching;
00154 pvector<pvector<NodePath> > _blocks;
00155 pvector<pvector<unsigned short> > _levels;
00156 pvector<pvector<unsigned short> > _old_levels;
00157
00158 public:
00159 static TypeHandle get_class_type() {
00160 return _type_handle;
00161 }
00162 static void init_type() {
00163 TypedObject::init_type();
00164 register_type(_type_handle, "GeoMipTerrain",
00165 TypedObject::get_class_type());
00166 }
00167 virtual TypeHandle get_type() const {
00168 return get_class_type();
00169 }
00170 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00171
00172 private:
00173 static TypeHandle _type_handle;
00174
00175 };
00176
00177 #include "geoMipTerrain.I"
00178
00179 #endif
00180