Panda3D

Loading...
Searching...
No Matches
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);
38PUBLISHED:
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
80 typedef pvector<SpeedTree::SVertexAttribDesc> VertexAttribs;
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 };
93 typedef pvector<SplatLayer> SplatLayers;
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
126INLINE 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
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
GeomVertexColumn
This defines how a single column is interleaved within a vertex array stored within a Geom.
Definition geomVertexColumn.h:37
GeomVertexData
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
Definition geomVertexData.h:68
GeomVertexFormat
This class defines the physical layout of the vertex data stored within a Geom.
Definition geomVertexFormat.h:55
Namable::output
void output(std::ostream &out) const
Outputs the Namable.
Definition namable.I:61
STTerrain
This is the abstract base class that defines the interface needed to describe a terrain for rendering...
Definition stTerrain.h:34
STTerrain::get_splat_layer
const Filename & get_splat_layer(int n) const
Returns the nth splat layer that is to be applied to the terrain.
Definition stTerrain.I:56
STTerrain::get_max_height
PN_stdfloat get_max_height() const
Returns the largest height value that might be returned by get_height().
Definition stTerrain.I:105
STTerrain::fill_vertices
virtual void fill_vertices(GeomVertexData *data, PN_stdfloat start_x, PN_stdfloat start_y, PN_stdfloat size_xy, int num_xy) const
After load_data() has been called, this will be called occasionally to populate the vertices for a te...
Definition stTerrain.cxx:143
STTerrain::get_smooth_height
virtual PN_stdfloat get_smooth_height(PN_stdfloat x, PN_stdfloat y, PN_stdfloat radius) const
After load_data() has been called, this should return the approximate average height value over a cir...
Definition stTerrain.cxx:95
STTerrain::get_st_vertex_format
const SpeedTree::SVertexAttribDesc * get_st_vertex_format() const
Returns a pointer to the SpeedTree array of vertex attribs that defines the vertex format for SpeedTr...
Definition stTerrain.cxx:170
STTerrain::get_min_height
PN_stdfloat get_min_height() const
Returns the smallest height value that might be returned by get_height().
Definition stTerrain.I:96
STTerrain::clear
virtual void clear()
Resets the terrain to its initial, unloaded state.
Definition stTerrain.cxx:56
STTerrain::get_vertex_format
const GeomVertexFormat * get_vertex_format()
Returns the vertex format of the vertex array that is supported by this terrain data.
Definition stTerrain.I:87
STTerrain::get_num_splat_layers
int get_num_splat_layers() const
Returns the number of splat layers that are to be applied to the terrain.
Definition stTerrain.I:48
STTerrain::get_splat_layer_color
LColor get_splat_layer_color(int n) const
Returns the overall color of the nth splat layer.
Definition stTerrain.I:76
STTerrain::get_height
virtual PN_stdfloat get_height(PN_stdfloat x, PN_stdfloat y) const =0
After load_data() has been called, this should return the computed height value at point (x,...
Definition stTerrain.cxx:85
STTerrain::placement_is_acceptable
bool placement_is_acceptable(PN_stdfloat x, PN_stdfloat y, PN_stdfloat height_min, PN_stdfloat height_max, PN_stdfloat slope_min, PN_stdfloat slope_max)
Returns true if the elevation and slope of point (x, y) fall within the requested limits,...
Definition stTerrain.cxx:115
STTerrain::get_normal_map
const Filename & get_normal_map() const
Returns the normal map that should be applied to the terrain.
Definition stTerrain.I:27
STTerrain::get_slope
virtual PN_stdfloat get_slope(PN_stdfloat x, PN_stdfloat y) const
After load_data() has been called, this should return the directionless slope at point (x,...
Definition stTerrain.cxx:106
STTerrain::is_valid
bool is_valid() const
Returns true if the terrain data is well-defined and ready to use.
Definition stTerrain.I:18
STTerrain::get_splat_map
const Filename & get_splat_map() const
Returns the splat map that should be applied to the terrain.
Definition stTerrain.I:38
STTerrain::get_splat_layer_tiling
PN_stdfloat get_splat_layer_tiling(int n) const
Returns the tiling value of the nth splat layer.
Definition stTerrain.I:66
STTerrain::load_data
virtual void load_data()=0
This will be called at some point after initialization.
Definition stTerrain.cxx:76
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
geomVertexData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
namable.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
speedtree_api.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
stTerrain.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.