Panda3D
 All Classes Functions Variables Enumerations
stTerrain.h
1 // Filename: stTerrain.h
2 // Created by: drose (11Oct10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef STTERRAIN_H
16 #define STTERRAIN_H
17 
18 #include "pandabase.h"
19 #include "typedReferenceCount.h"
20 #include "namable.h"
21 #include "geomVertexData.h"
22 #include "speedtree_api.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : STTerrain
26 // Description : This is the abstract base class that defines the
27 // interface needed to describe a terrain for rendering
28 // by SpeedTree. To use it, you must subclass and
29 // override the appropriate virtual methods. Or,
30 // consider just using STBasicTerrain.
31 //
32 // A terrain is defined as a 2-d height function over
33 // all space: get_height(x, y) may be called for any
34 // point in space and it should return a reasonable
35 // value. A terrain also provides normal maps and splat
36 // maps, as rendered by SpeedTree's Terrain.hlsl shader
37 // file.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDASPEEDTREE STTerrain : public TypedReferenceCount, public Namable {
40 protected:
41  STTerrain();
42  STTerrain(const STTerrain &copy);
43 PUBLISHED:
44  virtual ~STTerrain();
45 
46  virtual void clear();
47  virtual void load_data()=0;
48 
49  INLINE bool is_valid() const;
50 
51  INLINE const Filename &get_normal_map() const;
52  INLINE const Filename &get_splat_map() const;
53 
54  INLINE int get_num_splat_layers() const;
55  INLINE const Filename &get_splat_layer(int n) const;
56  INLINE PN_stdfloat get_splat_layer_tiling(int n) const;
57  INLINE LColor get_splat_layer_color(int n) const;
58 
59  INLINE const GeomVertexFormat *get_vertex_format();
60 
61  INLINE PN_stdfloat get_min_height() const;
62  INLINE PN_stdfloat get_max_height() const;
63 
64  virtual PN_stdfloat get_height(PN_stdfloat x, PN_stdfloat y) const=0;
65  virtual PN_stdfloat get_smooth_height(PN_stdfloat x, PN_stdfloat y, PN_stdfloat radius) const;
66  virtual PN_stdfloat get_slope(PN_stdfloat x, PN_stdfloat y) const;
67 
68  bool placement_is_acceptable(PN_stdfloat x, PN_stdfloat y,
69  PN_stdfloat height_min, PN_stdfloat height_max,
70  PN_stdfloat slope_min, PN_stdfloat slope_max);
71 
72  virtual void fill_vertices(GeomVertexData *data,
73  PN_stdfloat start_x, PN_stdfloat start_y,
74  PN_stdfloat size_xy, int num_xy) const;
75 
76  virtual void output(ostream &out) const;
77  virtual void write(ostream &out, int indent_level = 0) const;
78 
79 public:
80  const SpeedTree::SVertexAttribDesc *get_st_vertex_format() const;
81 
82 protected:
83  bool set_vertex_format(const GeomVertexFormat *format);
84 
86  static bool convert_vertex_format(VertexAttribs &st_vertex_attribs,
87  const GeomVertexFormat *format);
88  static bool convert_vertex_column(SpeedTree::SVertexAttribDesc &st_attrib,
89  const GeomVertexColumn *column);
90 
91 protected:
92  class SplatLayer {
93  public:
94  Filename _filename;
95  PN_stdfloat _tiling;
96  UnalignedLVecBase4 _color;
97  };
99 
100 protected:
101  bool _is_valid;
102 
103  Filename _normal_map;
104  Filename _splat_map;
105  SplatLayers _splat_layers;
106 
107  CPT(GeomVertexFormat) _vertex_format;
108  VertexAttribs _st_vertex_attribs;
109 
110  PN_stdfloat _min_height;
111  PN_stdfloat _max_height;
112 
113 public:
114  static TypeHandle get_class_type() {
115  return _type_handle;
116  }
117  static void init_type() {
118  TypedReferenceCount::init_type();
119  register_type(_type_handle, "STTerrain",
120  TypedReferenceCount::get_class_type());
121  }
122  virtual TypeHandle get_type() const {
123  return get_class_type();
124  }
125  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
126 
127 private:
128  static TypeHandle _type_handle;
129 };
130 
131 INLINE ostream &operator << (ostream &out, const STTerrain &terrain) {
132  terrain.output(out);
133  return out;
134 }
135 
136 #include "stTerrain.I"
137 
138 #endif
This is an &quot;unaligned&quot; LVecBase4.
Definition: lvecBase4.h:299
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
Definition: stTerrain.h:39
This defines how a single column is interleaved within a vertex array stored within a Geom...
A base class for all things which can have a name.
Definition: namable.h:29
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
void output(ostream &out) const
Outputs the Namable.
Definition: namable.I:97
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85