Clone this wiki locally

CubicVR.Landscape

The Landscape class is a SceneObject that generates and manages a heightfield. It can be bound to a scene using [[Scene]].bindSceneObject(..).

Currently it only accepts a single material and appears centered at [0,0,0] when added to the scene but will eventually have proper placement and texture spatting support.

Constructor:

Landscape( size, divisions_x, divisions_z, mat )

Parameters:

size : The total length of the axis with the largest number of divisions.

divisions_x : Total divisions on the X-axis.

divisions_z : Total divisions on the Z-axis.

mat : Material to apply.

Note that faces must have square dimensions on the X/Z axis and therefore only one size is supplied. If divisions_x and divisions_z do not match size will represent the axis with the highest number of divisions.

i.e. size of 1000.0 with divisions_x of 128 and divisions_z of 64 will yield a heightfield sized 1000.0 on the X-axis and 500.0 on the Z-axis.

To complete the Landscape you should apply a UVMapper (if required for textured materials) and call myLandscape.getMesh().calcNormals().compile(); to prepare it for rendering.

Methods:

getMesh()

Return the Mesh generated for the heightfield. This is required for applying UV, calculating normals and compiling for use in a Scene.

setIndexedHeight( ipos, jpos, val )

Set the height of the given point index (in divisions) on the X and Z axis.

Parameters:

x : Index from 0 to < divisions_x along the X-axis.

z : Index from 0 to < divisions_z along the Z-axis.

val : Y value to set at the given X/Z location.

Returns:

Height (Y-axis) value of the heightfield at the given X/Z coordinates.

mapGen( w_func, ipos, jpos, ilen, jlen )

Step through each point on the heightfield and use the value returned from the supplied function w_func. If index parameters are not supplied it will assume to process the entire field.

Parameters:

w_func : The function called for each point on the heightfield to be evaluated. Format is function(x, z) {} and must return the desired Y-axis value at the given X/Z.

ipos (optional) : Index from 0 to < divisions_x along the X-axis to start.

jpos (optional) : Index from 0 to < divisions_z along the Z-axis to start.

ilen (optional) : Number of X-axis divisions to walk.

jlen (optional) : Number of Z-axis divisions to walk.

Returns:

none

getHeightValue( x, z ) or getHeightValue( pt )

Get the Y height value of a given position on the X/Z plane.

Parameters:

x : Position on the X-axis.

z : Position on the Z-axis.

pt : A point in the format [ x, y, z ] (y-value will be ignored).

Returns:

Height (Y-axis) value of the heightfield at the given X/Z coordinates.

orient( x, z, width, length, heading )

Get the resulting position and rotation for an object to rest on the heightfield given it's position, base dimensions and heading on the X/Z plane. Additional work is done to ensure the base of the object does not intersect the heightfield.

Parameters:

x : Position on the X-axis.

z : Position on the Z-axis.

width : The width of the base of the object to orient (local X-axis).

length : The length of the base of the object to orient (local Z-axis).