Panda3D
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
STBasicTerrain Class Reference

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"

Inheritance diagram for STBasicTerrain:
STTerrain TypedReferenceCount Namable TypedObject ReferenceCount MemoryBase MemoryBase MemoryBase

List of all members.

Classes

class  InterpolationData

Public Member Functions

 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.
void clear ()
 Resets the terrain to its initial, unloaded state.
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.
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.
const Filenameget_height_map () const
 Returns the image filename that defines the height map of the terrain.
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.
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.
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.
virtual TypeHandle get_type () const
virtual void load_data ()
 This will be called at some point after initialization.
virtual void output (ostream &out) const
 Outputs the Namable.
void set_height_map (const Filename &height_map)
 Specifies the image filename that will define the height map of the terrain.
bool setup_terrain (const Filename &terrain_filename)
 Sets up the terrain by reading a terrain.txt file as defined by SpeedTree.
bool setup_terrain (istream &in, const Filename &pathname)
 Sets up the terrain by reading a terrain.txt file as defined by SpeedTree.
virtual void write (ostream &out, int indent_level=0) const

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()

Protected Member Functions

void compute_slope (PN_stdfloat smoothing)
 Once _height_data has been filled in, compute the corresponding values for _slope_data.
PN_stdfloat interpolate (PN_stdfloat a, PN_stdfloat b, PN_stdfloat t)
 Convenience function to calculate the linear interpolation from A to B.
bool read_height_map ()
 Reads the height map image stored in _height_map, and stores it in _height_data.

Protected Attributes

InterpolationData< PN_stdfloat > _height_data
Filename _height_map
PN_stdfloat _height_scale
PN_stdfloat _size
InterpolationData< PN_stdfloat > _slope_data

Detailed Description

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 30 of file stBasicTerrain.h.


Constructor & Destructor Documentation

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 60 of file stBasicTerrain.cxx.


Member Function Documentation

void STBasicTerrain::clear ( ) [virtual]

Resets the terrain to its initial, unloaded state.

Reimplemented from STTerrain.

Definition at line 82 of file stBasicTerrain.cxx.

References STTerrain::set_vertex_format().

Referenced by setup_terrain().

void STBasicTerrain::compute_slope ( PN_stdfloat  smoothing) [protected]

Once _height_data has been filled in, compute the corresponding values for _slope_data.

Definition at line 410 of file stBasicTerrain.cxx.

References interpolate(), and STBasicTerrain::InterpolationData< ValueType >::reset().

Referenced by read_height_map().

void STBasicTerrain::fill_vertices ( GeomVertexData data,
PN_stdfloat  start_x,
PN_stdfloat  start_y,
PN_stdfloat  size_xy,
int  num_xy 
) const [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 321 of file stBasicTerrain.cxx.

References GeomVertexData::get_format(), get_height(), and GeomVertexWriter::set_data3().

PN_stdfloat STBasicTerrain::get_height ( PN_stdfloat  x,
PN_stdfloat  y 
) const [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 272 of file stBasicTerrain.cxx.

References STBasicTerrain::InterpolationData< ValueType >::calc_bilinear_interpolation().

Referenced by fill_vertices(), STTerrain::get_smooth_height(), and STTerrain::placement_is_acceptable().

const Filename & STBasicTerrain::get_height_map ( ) const [inline]

Returns the image filename that defines the height map of the terrain.

Definition at line 37 of file stBasicTerrain.I.

PN_stdfloat STBasicTerrain::get_size ( ) const [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 50 of file stBasicTerrain.I.

PN_stdfloat STBasicTerrain::get_slope ( PN_stdfloat  x,
PN_stdfloat  y 
) const [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 299 of file stBasicTerrain.cxx.

References STBasicTerrain::InterpolationData< ValueType >::calc_bilinear_interpolation().

Referenced by STTerrain::placement_is_acceptable().

PN_stdfloat STBasicTerrain::get_smooth_height ( PN_stdfloat  x,
PN_stdfloat  y,
PN_stdfloat  radius 
) const [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 285 of file stBasicTerrain.cxx.

References STBasicTerrain::InterpolationData< ValueType >::calc_smooth().

PN_stdfloat STBasicTerrain::interpolate ( PN_stdfloat  a,
PN_stdfloat  b,
PN_stdfloat  t 
) [inline, protected]

Convenience function to calculate the linear interpolation from A to B.

Definition at line 61 of file stBasicTerrain.I.

Referenced by compute_slope().

void STBasicTerrain::load_data ( ) [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 253 of file stBasicTerrain.cxx.

References read_height_map().

Referenced by setup_terrain().

void STBasicTerrain::output ( ostream &  out) const [virtual]

Outputs the Namable.

This function simply writes the name to the output stream; most Namable derivatives will probably redefine this.

Reimplemented from STTerrain.

Definition at line 351 of file stBasicTerrain.cxx.

Referenced by STTerrain::output().

bool STBasicTerrain::read_height_map ( ) [protected]

Reads the height map image stored in _height_map, and stores it in _height_data.

Returns true on success, false on failure.

Definition at line 374 of file stBasicTerrain.cxx.

References compute_slope(), PNMImageHeader::get_num_channels(), PNMImageHeader::get_x_size(), PNMImage::get_xel_a(), PNMImageHeader::get_y_size(), PNMImage::is_valid(), and STBasicTerrain::InterpolationData< ValueType >::reset().

Referenced by load_data().

void STBasicTerrain::set_height_map ( const Filename height_map) [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 25 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 110 of file stBasicTerrain.cxx.

References Filename::get_basename(), and VirtualFileSystem::get_global_ptr().

bool STBasicTerrain::setup_terrain ( 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 153 of file stBasicTerrain.cxx.

References clear(), Filename::get_dirname(), and load_data().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations