A specific implementation of STTerrain that supports basic heightmaps loaded from an image file, as described in a terrain.txt file similar to those provided with the SpeedTree example application. More...
#include "stBasicTerrain.h"
Public Member Functions | |
STBasicTerrain (const STBasicTerrain ©) | |
Not sure whether any derived classes will implement the copy constructor, but it's defined here at the base level just in case. More... | |
void | clear () |
Resets the terrain to its initial, unloaded state. More... | |
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 terrain cell. More... | |
virtual TypeHandle | force_init_type () |
virtual PN_stdfloat | get_height (PN_stdfloat x, PN_stdfloat y) const |
After load_data() has been called, this should return the computed height value at point (x, y) of the terrain, where x and y are unbounded and may refer to any 2-d point in space. More... | |
const Filename & | get_height_map () const |
Returns the image filename that defines the height map of the terrain. More... | |
PN_stdfloat | get_size () const |
Returns the length, in scene graph units, of one edge of the heightmap as it is manifested by the terrain. More... | |
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, y) of the terrain, where 0.0 is flat and 1.0 is vertical. More... | |
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 circle of the specified radius, centered at point (x, y) of the terrain. More... | |
virtual TypeHandle | get_type () const |
virtual void | load_data () |
This will be called at some point after initialization. More... | |
virtual void | output (std::ostream &out) const |
void | set_height_map (const Filename &height_map) |
Specifies the image filename that will define the height map of the terrain. More... | |
bool | setup_terrain (const Filename &terrain_filename) |
Sets up the terrain by reading a terrain.txt file as defined by SpeedTree. More... | |
bool | setup_terrain (std::istream &in, const Filename &pathname) |
Sets up the terrain by reading a terrain.txt file as defined by SpeedTree. More... | |
virtual void | write (std::ostream &out, int indent_level=0) const |
Public Member Functions inherited from STTerrain | |
PN_stdfloat | get_max_height () const |
Returns the largest height value that might be returned by get_height(). More... | |
PN_stdfloat | get_min_height () const |
Returns the smallest height value that might be returned by get_height(). More... | |
const Filename & | get_normal_map () const |
Returns the normal map that should be applied to the terrain. More... | |
int | get_num_splat_layers () const |
Returns the number of splat layers that are to be applied to the terrain. More... | |
const Filename & | get_splat_layer (int n) const |
Returns the nth splat layer that is to be applied to the terrain. More... | |
LColor | get_splat_layer_color (int n) const |
Returns the overall color of the nth splat layer. More... | |
PN_stdfloat | get_splat_layer_tiling (int n) const |
Returns the tiling value of the nth splat layer. More... | |
const Filename & | get_splat_map () const |
Returns the splat map that should be applied to the terrain. More... | |
const SpeedTree::SVertexAttribDesc * | get_st_vertex_format () const |
Returns a pointer to the SpeedTree array of vertex attribs that defines the vertex format for SpeedTree. More... | |
const GeomVertexFormat * | get_vertex_format () |
Returns the vertex format of the vertex array that is supported by this terrain data. More... | |
bool | is_valid () const |
Returns true if the terrain data is well-defined and ready to use. More... | |
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, false otherwise. More... | |
Public Member Functions inherited from TypedReferenceCount | |
TypedReferenceCount (const TypedReferenceCount ©) | |
void | operator= (const TypedReferenceCount ©) |
Public Member Functions inherited from TypedObject | |
TypedObject (const TypedObject ©)=default | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
int | get_best_parent_from_Set (const std::set< int > &) const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More... | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. More... | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. More... | |
TypedObject & | operator= (const TypedObject ©)=default |
Public Member Functions inherited from ReferenceCount | |
int | get_ref_count () const |
WeakReferenceList * | get_weak_list () const |
Returns the WeakReferenceList associated with this ReferenceCount object. More... | |
bool | has_weak_list () const |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More... | |
void | local_object () |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More... | |
void | ref () const |
Explicitly increments the reference count. More... | |
bool | ref_if_nonzero () const |
Atomically increases the reference count of this object if it is not zero. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | test_ref_count_nonzero () const |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
virtual bool | unref () const |
Explicitly decrements the reference count. More... | |
WeakReferenceList * | weak_ref () |
Adds the indicated PointerToVoid as a weak reference to this object. More... | |
void | weak_unref () |
Removes the indicated PointerToVoid as a weak reference to this object. More... | |
Public Member Functions inherited from Namable | |
Namable (const std::string &initial_name="") | |
void | clear_name () |
Resets the Namable's name to empty. More... | |
const std::string & | get_name () const |
bool | has_name () const |
Returns true if the Namable has a nonempty name set, false if the name is empty. More... | |
void | output (std::ostream &out) const |
Outputs the Namable. More... | |
void | set_name (const std::string &name) |
Static Public Member Functions | |
static TypeHandle | get_class_type () |
static void | init_type () |
Static Public Member Functions inherited from STTerrain | |
static TypeHandle | get_class_type () |
static void | init_type () |
Static Public Member Functions inherited from TypedReferenceCount | |
static TypeHandle | get_class_type () |
static void | init_type () |
Static Public Member Functions inherited from TypedObject | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. More... | |
Static Public Member Functions inherited from ReferenceCount | |
static TypeHandle | get_class_type () |
static void | init_type () |
Static Public Member Functions inherited from Namable | |
static TypeHandle | get_class_type () |
static void | init_type () |
Additional Inherited Members | |
Public Attributes inherited from TypedObject | |
get_type | |
Public Attributes inherited from ReferenceCount | |
get_ref_count | |
Returns the current reference count. More... | |
Public Attributes inherited from Namable | |
get_name | |
set_name | |
A specific implementation of STTerrain that supports basic heightmaps loaded from an image file, as described in a terrain.txt file similar to those provided with the SpeedTree example application.
Definition at line 27 of file stBasicTerrain.h.
STBasicTerrain::STBasicTerrain | ( | const STBasicTerrain & | copy | ) |
Not sure whether any derived classes will implement the copy constructor, but it's defined here at the base level just in case.
Definition at line 58 of file stBasicTerrain.cxx.
|
virtual |
Resets the terrain to its initial, unloaded state.
Reimplemented from STTerrain.
Definition at line 76 of file stBasicTerrain.cxx.
References STTerrain::clear().
Referenced by setup_terrain().
|
virtual |
After load_data() has been called, this will be called occasionally to populate the vertices for a terrain cell.
It will be passed a GeomVertexData whose format will match get_vertex_format(), and already allocated with num_xy * num_xy rows. This method should fill the rows of the data with the appropriate vertex data for the terrain, over the grid described by the corners (start_x, start_y) up to and including (start_x + size_x, start_y + size_xy)–a square of the terrain with num_xy vertices on a size, arranged in row-major order.
Reimplemented from STTerrain.
Definition at line 287 of file stBasicTerrain.cxx.
|
virtual |
After load_data() has been called, this should return the computed height value at point (x, y) of the terrain, where x and y are unbounded and may refer to any 2-d point in space.
Implements STTerrain.
Definition at line 250 of file stBasicTerrain.cxx.
|
inline |
Returns the image filename that defines the height map of the terrain.
Definition at line 29 of file stBasicTerrain.I.
|
inline |
Returns the length, in scene graph units, of one edge of the heightmap as it is manifested by the terrain.
Increasing this number spreads the heightmap out over a greater area.
Definition at line 39 of file stBasicTerrain.I.
|
virtual |
After load_data() has been called, this should return the directionless slope at point (x, y) of the terrain, where 0.0 is flat and 1.0 is vertical.
This is used for determining the legal points to place trees and grass.
Reimplemented from STTerrain.
Definition at line 271 of file stBasicTerrain.cxx.
|
virtual |
After load_data() has been called, this should return the approximate average height value over a circle of the specified radius, centered at point (x, y) of the terrain.
Reimplemented from STTerrain.
Definition at line 260 of file stBasicTerrain.cxx.
|
virtual |
This will be called at some point after initialization.
It should be overridden by a derived class to load up the terrain data from its source and fill in the data members of this class appropriately, especially _is_valid. After this call, if _is_valid is true, then get_height() etc. will be called to query the terrain's data.
Implements STTerrain.
Definition at line 234 of file stBasicTerrain.cxx.
|
inline |
Specifies the image filename that will define the height map of the terrain.
This will require a subsequent call to load_data() to actually read the data.
Definition at line 20 of file stBasicTerrain.I.
bool STBasicTerrain::setup_terrain | ( | const Filename & | terrain_filename | ) |
Sets up the terrain by reading a terrain.txt file as defined by SpeedTree.
This file names the various map files that define the terrain, as well as defining parameters size as its size and color.
If a relative filename is supplied, the model-path is searched. If a directory is named, "terrain.txt" is implicitly appended.
Definition at line 100 of file stBasicTerrain.cxx.
References Filename::get_basename().
bool STBasicTerrain::setup_terrain | ( | std::istream & | in, |
const Filename & | pathname | ||
) |
Sets up the terrain by reading a terrain.txt file as defined by SpeedTree.
This variant on this method accepts an istream for an already-opened terrain.txt file. The filename is provided for reference, to assist relative file operations. It should name the terrain.txt file that has been opened.
Definition at line 140 of file stBasicTerrain.cxx.
References clear(), and Filename::get_dirname().