Panda3D
|
00001 // Filename: stTerrain.h 00002 // Created by: drose (11Oct10) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef STTERRAIN_H 00016 #define STTERRAIN_H 00017 00018 #include "pandabase.h" 00019 #include "typedReferenceCount.h" 00020 #include "namable.h" 00021 #include "geomVertexData.h" 00022 #include "speedtree_api.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Class : STTerrain 00026 // Description : This is the abstract base class that defines the 00027 // interface needed to describe a terrain for rendering 00028 // by SpeedTree. To use it, you must subclass and 00029 // override the appropriate virtual methods. Or, 00030 // consider just using STBasicTerrain. 00031 // 00032 // A terrain is defined as a 2-d height function over 00033 // all space: get_height(x, y) may be called for any 00034 // point in space and it should return a reasonable 00035 // value. A terrain also provides normal maps and splat 00036 // maps, as rendered by SpeedTree's Terrain.hlsl shader 00037 // file. 00038 //////////////////////////////////////////////////////////////////// 00039 class EXPCL_PANDASPEEDTREE STTerrain : public TypedReferenceCount, public Namable { 00040 protected: 00041 STTerrain(); 00042 STTerrain(const STTerrain ©); 00043 PUBLISHED: 00044 virtual ~STTerrain(); 00045 00046 virtual void clear(); 00047 virtual void load_data()=0; 00048 00049 INLINE bool is_valid() const; 00050 00051 INLINE const Filename &get_normal_map() const; 00052 INLINE const Filename &get_splat_map() const; 00053 00054 INLINE int get_num_splat_layers() const; 00055 INLINE const Filename &get_splat_layer(int n) const; 00056 INLINE PN_stdfloat get_splat_layer_tiling(int n) const; 00057 INLINE LColor get_splat_layer_color(int n) const; 00058 00059 INLINE const GeomVertexFormat *get_vertex_format(); 00060 00061 INLINE PN_stdfloat get_min_height() const; 00062 INLINE PN_stdfloat get_max_height() const; 00063 00064 virtual PN_stdfloat get_height(PN_stdfloat x, PN_stdfloat y) const=0; 00065 virtual PN_stdfloat get_smooth_height(PN_stdfloat x, PN_stdfloat y, PN_stdfloat radius) const; 00066 virtual PN_stdfloat get_slope(PN_stdfloat x, PN_stdfloat y) const; 00067 00068 bool placement_is_acceptable(PN_stdfloat x, PN_stdfloat y, 00069 PN_stdfloat height_min, PN_stdfloat height_max, 00070 PN_stdfloat slope_min, PN_stdfloat slope_max); 00071 00072 virtual void fill_vertices(GeomVertexData *data, 00073 PN_stdfloat start_x, PN_stdfloat start_y, 00074 PN_stdfloat size_xy, int num_xy) const; 00075 00076 virtual void output(ostream &out) const; 00077 virtual void write(ostream &out, int indent_level = 0) const; 00078 00079 public: 00080 const SpeedTree::SVertexAttribDesc *get_st_vertex_format() const; 00081 00082 protected: 00083 bool set_vertex_format(const GeomVertexFormat *format); 00084 00085 typedef pvector<SpeedTree::SVertexAttribDesc> VertexAttribs; 00086 static bool convert_vertex_format(VertexAttribs &st_vertex_attribs, 00087 const GeomVertexFormat *format); 00088 static bool convert_vertex_column(SpeedTree::SVertexAttribDesc &st_attrib, 00089 const GeomVertexColumn *column); 00090 00091 protected: 00092 class SplatLayer { 00093 public: 00094 Filename _filename; 00095 PN_stdfloat _tiling; 00096 UnalignedLVecBase4 _color; 00097 }; 00098 typedef pvector<SplatLayer> SplatLayers; 00099 00100 protected: 00101 bool _is_valid; 00102 00103 Filename _normal_map; 00104 Filename _splat_map; 00105 SplatLayers _splat_layers; 00106 00107 CPT(GeomVertexFormat) _vertex_format; 00108 VertexAttribs _st_vertex_attribs; 00109 00110 PN_stdfloat _min_height; 00111 PN_stdfloat _max_height; 00112 00113 public: 00114 static TypeHandle get_class_type() { 00115 return _type_handle; 00116 } 00117 static void init_type() { 00118 TypedReferenceCount::init_type(); 00119 register_type(_type_handle, "STTerrain", 00120 TypedReferenceCount::get_class_type()); 00121 } 00122 virtual TypeHandle get_type() const { 00123 return get_class_type(); 00124 } 00125 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00126 00127 private: 00128 static TypeHandle _type_handle; 00129 }; 00130 00131 INLINE ostream &operator << (ostream &out, const STTerrain &terrain) { 00132 terrain.output(out); 00133 return out; 00134 } 00135 00136 #include "stTerrain.I" 00137 00138 #endif