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