00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef STBASICTERRAIN_H
00016 #define STBASICTERRAIN_H
00017
00018 #include "pandabase.h"
00019 #include "stTerrain.h"
00020 #include "luse.h"
00021 #include "pvector.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030 class EXPCL_PANDASPEEDTREE STBasicTerrain : public STTerrain {
00031 PUBLISHED:
00032 STBasicTerrain();
00033 STBasicTerrain(const STBasicTerrain ©);
00034 virtual ~STBasicTerrain();
00035
00036 void clear();
00037
00038 bool setup_terrain(const Filename &terrain_filename);
00039 bool setup_terrain(istream &in, const Filename &pathname);
00040
00041 INLINE void set_height_map(const Filename &height_map);
00042 INLINE const Filename &get_height_map() const;
00043
00044 virtual void load_data();
00045
00046 INLINE PN_stdfloat get_size() const;
00047 virtual PN_stdfloat get_height(PN_stdfloat x, PN_stdfloat y) const;
00048 virtual PN_stdfloat get_smooth_height(PN_stdfloat x, PN_stdfloat y, PN_stdfloat radius) const;
00049 virtual PN_stdfloat get_slope(PN_stdfloat x, PN_stdfloat y) const;
00050
00051 virtual void fill_vertices(GeomVertexData *data,
00052 PN_stdfloat start_x, PN_stdfloat start_y,
00053 PN_stdfloat size_xy, int num_xy) const;
00054
00055 virtual void output(ostream &out) const;
00056 virtual void write(ostream &out, int indent_level = 0) const;
00057
00058 protected:
00059 bool read_height_map();
00060 void compute_slope(PN_stdfloat smoothing);
00061
00062 INLINE PN_stdfloat interpolate(PN_stdfloat a, PN_stdfloat b, PN_stdfloat t);
00063
00064 private:
00065 static void read_quoted_filename(Filename &result, istream &in,
00066 const Filename &dirname);
00067
00068 protected:
00069 template<class ValueType>
00070 class InterpolationData {
00071 public:
00072 InterpolationData();
00073 void reset(int width, int height);
00074
00075 ValueType get_nearest_neighbor(PN_stdfloat u, PN_stdfloat v) const;
00076 ValueType calc_bilinear_interpolation(PN_stdfloat u, PN_stdfloat v) const;
00077 ValueType calc_smooth(PN_stdfloat u, PN_stdfloat v, PN_stdfloat radius) const;
00078 bool is_present() const;
00079
00080 int _width;
00081 int _height;
00082 pvector<ValueType> _data;
00083 };
00084
00085 protected:
00086 Filename _height_map;
00087 PN_stdfloat _size;
00088 PN_stdfloat _height_scale;
00089
00090 InterpolationData<PN_stdfloat> _height_data;
00091
00092 InterpolationData<PN_stdfloat> _slope_data;
00093
00094
00095 public:
00096 static TypeHandle get_class_type() {
00097 return _type_handle;
00098 }
00099 static void init_type() {
00100 STTerrain::init_type();
00101 register_type(_type_handle, "STBasicTerrain",
00102 STTerrain::get_class_type());
00103 }
00104 virtual TypeHandle get_type() const {
00105 return get_class_type();
00106 }
00107 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00108
00109 private:
00110 static TypeHandle _type_handle;
00111 };
00112
00113 #include "stBasicTerrain.I"
00114
00115 #endif