Click or drag to resize
DigitalRuneHeightField Class
Represents a height field which can be used for simple terrains.
Inheritance Hierarchy

Namespace: DigitalRune.Geometry.Shapes
Assembly: DigitalRune.Geometry (in DigitalRune.Geometry.dll) Version: 1.18.0.0 (1.18.2.14427)
Syntax
public class HeightField : Shape

The HeightField type exposes the following members.

Constructors
Methods
  NameDescription
Public methodClone
Creates a new Shape that is a clone (deep copy) of the current instance.
(Inherited from Shape.)
Protected methodCloneCore
Makes the instance a clone (deep copy) of the specified Shape.
(Overrides ShapeCloneCore(Shape).)
Protected methodCreateInstanceCore
When implemented in a derived class, creates a new instance of the Shape derived class.
(Overrides ShapeCreateInstanceCore.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetAabb
Computes the axis-aligned bounding box (AABB) for this shape in local space.
(Inherited from Shape.)
Public methodGetAabb(Pose)
Computes the axis-aligned bounding box (AABB) for this shape positioned in world space using the given Pose.
(Inherited from Shape.)
Public methodGetAabb(Vector3F, Pose)
Computes the axis-aligned bounding box (AABB) for this shape positioned in world space using the given scale and Pose.
(Overrides ShapeGetAabb(Vector3F, Pose).)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetHeight
Gets the height for a height field coordinate.
Public methodGetMesh
Gets a mesh that represents this shape.
(Inherited from Shape.)
Public methodGetTriangle
Gets a triangle representing a part of a height field cell.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetVolume
Gets the volume of this shape.
(Overrides ShapeGetVolume(Single, Int32).)
Public methodInvalidate
Invalidates this height field.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnChanged
Raises the Changed event.
(Overrides ShapeOnChanged(ShapeChangedEventArgs).)
Protected methodOnGetMesh
Called when a mesh should be generated for the shape.
(Overrides ShapeOnGetMesh(Single, Int32).)
Public methodSetSamples
Sets the array of height samples.
Public methodToString
Returns a String that represents the current Object.
(Overrides ObjectToString.)
Top
Properties
  NameDescription
Public propertyArray Obsolete.
Gets or sets the height field.
Public propertyDepth
Gets or sets the depth of the height field.
Public propertyInnerPoint
Gets an inner point.
(Overrides ShapeInnerPoint.)
Public propertyNumberOfSamplesX
Gets the number of samples per row (= along the x-axis).
Public propertyNumberOfSamplesZ
Gets the number of samples per column (= along the z-axis).
Public propertyOriginX
Gets or sets height field origin along the x-axis.
Public propertyOriginZ
Gets or sets height field origin along the z-axis.
Public propertySamples
Gets the height field.
Public propertyUseFastCollisionApproximation
Gets or sets a value indicating whether the collision detection should use a fast, less accurate method.
Public propertyWidthX
Gets or sets the width along the local x-axis.
Public propertyWidthZ
Gets or sets the width along the local z-axis.
Top
Events
  NameDescription
Public eventChanged
Occurs when the shape was changed.
(Inherited from Shape.)
Top
Remarks

A height field is defined by a 1-dimensional array (Samples) which contains NumberOfSamplesX x NumberOfSamplesZ height values. This array is triangulated. Each array element defines a triangle vertex. The height samples are addressed like this:

height(indexX, indexZ) = Samples[indexZ * NumberOfSamplesX + indexX]

The height field is placed in the local x/z plane where the up direction is the positive y-axis. The top-left height field corner (Samples[0]) is positioned at x = OriginX and z = OriginZ.

The height field is stretched to fill a rectangle WidthX x WidthZ.

Holes in the height field can be created by setting a height value in the Samples to NaN. All triangles touching the "hole" vertex will be removed. This also means that the shape of the hole depends on the current tessellation pattern. If all elements in the Samples are NaN, then the behavior of the height field is undefined.

Limitations of holes and collision detection: Please note that computation of ClosestPoints, might not work as expected if an object moves through a hole and under the height field. Also computation of contacts might not work as expected on the border triangles near the hole. For good collision detection results it is recommended to avoid closest points queries for objects under the height field and to always surround a hole with other collision objects. For instance if there is a cave in a game terrain, make the hole larger than the cave entrance and surround it with additional rock meshes.

Shape Features: If a HeightField is involved in a Contact the shape feature property (FeatureA or FeatureB) contains the index of the triangle that creates the Contact: Each cell consists of two triangles. The first cell contains the triangles 0 and 1. The next cell in positive x direction contains the triangles 2 and 3. And so on. To compute an index all cells of a row in positive x direction are enumerated then the next x-row is enumerated and so on.

Examples

Here is an example (pseudo-code):

HeightField { Samples=float[200], OriginX=3000, OriginY =4000, WidthX=100, WidthZ=200 }

This creates a height field in the x/z plane. The field is 100 units wide in the x-axis and 200 units wide in the z-axis. The array element [0] defines the height field height at x = 3000, z = 4000. The array element [199] defines the height field height at x = 3100, z = 4200

The HeightField must contain at least 2 x 2 elements.

For best performance, IGeometricObjects that have a HeightField shape should use only 90 degree rotations in their Pose. The local x/z plane of the height field should be normal to a world space axis plane.

For a height field the collision behavior is only defined in the x/z range of the height field. Beyond the height field limits the collision behavior is undefined. For example, if a box is left of the height field and moves sideways into the height field, the closest-point and contact information might not be intuitive and such cases should be avoided.

See Also