Table of Contents

Class Terrain

Namespace
OmegaEngine.Graphics.Renderables
Assembly
OmegaEngine.dll

Displays a multi-textured terrain

public class Terrain : Model, IDisposable, IPositionable
Inheritance
object
Terrain
Implements
Inherited Members

Constructors

Terrain(Mesh, XMaterial, bool)

Internal helper constructor

protected Terrain(Mesh sourceMesh, XMaterial material, bool lighting)

Parameters

sourceMesh Mesh

The finished terrain mesh in SlimDX.Direct3D9.Pool.SystemMemory. Disposed once its content has been copied and published.

material XMaterial

The material to use for rendering the terrain

lighting bool

Use/support lighting when rendering this terrain?

Remarks

Unlike other Models the terrain keeps no system memory copy of its mesh; it is by far the largest mesh in a scene. It is published without SlimDX.Direct3D9.MeshFlags.WriteOnly instead, so ModifyColor(Point, Color[,]) and ModifyHeight(Point, byte[,]) keep working.

Properties

Lighting

Use/support lighting when rendering this terrain?

public bool Lighting { get; }

Property Value

bool

PreCheckBounding

Controls whether intersection tests first check the bounding bodies to filter out broad misses.

protected override bool PreCheckBounding { get; }

Property Value

bool

Remarks

Turn this off for bodies whose bounding bodies nearly every ray hits anyway.

Size

The size of the terrain in game units

public Size Size { get; }

Property Value

Size

StretchH

A factor by which the terrain is horizontally stretched

public float StretchH { get; }

Property Value

float

StretchV

A factor by which the terrain is vertically stretched

public float StretchV { get; }

Property Value

float

Methods

Create(Engine, Size, float, float, ByteGrid, NibbleGrid, string?[], ByteVector4Grid?, bool, int)

Creates a new terrain from a height-map and a texture-map

public static Terrain Create(Engine engine, Size size, float stretchH, float stretchV, ByteGrid heightMap, NibbleGrid textureMap, string?[] textures, ByteVector4Grid? occlusionIntervalMap, bool lighting, int blockSize)

Parameters

engine Engine

The Engine to create the terrain in

size Size

The size of the terrain

stretchH float

A factor by which all horizontal distances are multiplied

stretchV float

A factor by which all vertical distances are multiplied

heightMap ByteGrid

The height values of the terrain in a 2D array. Grid size = Terrain size

textureMap NibbleGrid

The texture values of the terrain in a 2D array. Grid size = Terrain size / 3

textures string[]

An array with a maximum of 16 texture names associated to textureMap

occlusionIntervalMap ByteVector4Grid

The angles at which the global light source occlusion begins and ends. Grid size = Terrain size; may be null for no shadowing

lighting bool

Shall this mesh be prepared for lighting? (calculate normal vectors, make shaders support lighting, ...)

blockSize int

How many points in X and Y direction shall one block for culling be?

Returns

Terrain

The newly created terrain

Exceptions

FileNotFoundException

One of the specified texture files could not be found.

IOException

There was an error reading one of the texture files.

UnauthorizedAccessException

Read access to one of the texture files is not permitted.

InvalidDataException

One of the texture files does not contain a valid texture.

GetFacePosition(int, float, float)

protected virtual Vector3 GetFacePosition(int faceIndex, float u, float v)

Parameters

faceIndex int
u float
v float

Returns

Vector3

IntersectsGeometry(Ray, out float)

Determine whether the geometry of this PositionableRenderable is intersected by a ray in entity space.

protected override bool IntersectsGeometry(Ray ray, out float distance)

Parameters

ray Ray

A ray in entity space (the space BoundingSphere and BoundingBox live in, even before applying PreTransform) along which to check for intersections. Its direction is not normalized, so that distances keep the scale of the original ray.

distance float

Returns the distance along the ray at which the intersection took place.

Returns

bool

true if this PositionableRenderable was intersected by the ray.

Remarks

Only called if the ray passes the bounding bodies, unless PreCheckBounding is off.

ModifyColor(Point, Color[,])

Modifies the color of a part of the terrain.

public void ModifyColor(Point start, Color[,] partialColorMap)

Parameters

start Point

The top-left index of the area to modify.

partialColorMap Color[,]

A 2D array containing the new color values - array size specifies size of the area to modify.

Remarks

Cannot be called when Lighting is false, because coloring uses the lighting subsystem.

ModifyHeight(Point, byte[,])

Modifies the height of a part of the terrain.

public void ModifyHeight(Point start, byte[,] partialHeightMap)

Parameters

start Point

The top-left index of the area to modify.

partialHeightMap byte[,]

A 2D array containing the new height values; array size specifies size of the area to modify.

Remarks

Cannot be called when Lighting is true, because normals are not updated. Invalidates all internal SlimDX.BoundingBoxes.