Heightfield Class
Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a given distance.
Constructor
Heightfield
-
data
-
options
Parameters:
-
data
ArrayAn array of Y values that will be used to construct the terrain.
-
options
Object-
[minValue]
Number optionalMinimum value of the data points in the data array. Will be computed automatically if not given.
-
[maxValue]
Number optionalMaximum value.
-
[elementSize=0.1]
Number optionalWorld spacing between the data points in X direction.
-
Example:
// Generate some height data (y-values).
var data = [];
for(var i = 0; i < 1000; i++){
var y = 0.5 * Math.cos(0.2 * i);
data.push(y);
}
// Create the heightfield shape
var heightfieldShape = new Heightfield(data, {
elementSize: 1 // Distance between the data points in X and Y directions
});
var heightfieldBody = new Body();
heightfieldBody.addShape(heightfieldShape);
world.addBody(heightfieldBody);
Item Index
Methods
Methods
calculateLocalInertia
()
Vec3
Calculates the inertia in the local frame for this shape.
Returns:
getConvexTrianglePillar
-
i
-
j
-
getUpperTriangle
Get a triangle in the terrain in the form of a triangular convex shape.
Parameters:
-
i
Integer -
j
Integer -
getUpperTriangle
Boolean
getIndexOfPosition
-
x
-
y
-
result
-
clamp
Get the index of a local position on the heightfield. The indexes indicate the rectangles, so if your terrain is made of N x N height data points, you will have rectangle indexes ranging from 0 to N-1.
Parameters:
-
x
Number -
y
Number -
result
ArrayTwo-element array
-
clamp
BooleanIf the position should be clamped to the heightfield edge.
Returns:
getRectMinMax
-
iMinX
-
iMinY
-
iMaxX
-
iMaxY
-
[result]
Get max/min in a rectangle in the matrix data
Parameters:
-
iMinX
Integer -
iMinY
Integer -
iMaxX
Integer -
iMaxY
Integer -
[result]
Array optionalAn array to store the results in.
Returns:
The result array, if it was passed in. Minimum will be at position 0 and max at 1.
setHeightValueAtIndex
-
xi
-
yi
-
value
Set the height value at an index. Don't forget to update maxValue and minValue after you're done.
Parameters:
-
xi
Integer -
yi
Integer -
value
Number
update
()
Call whenever you change the data array.
updateBoundingSphereRadius
()
Number
Computes the bounding sphere radius. The result is stored in the property .boundingSphereRadius
Returns:
updateMaxValue
()
Update the .maxValue property
updateMinValue
()
Update the .minValue property
volume
()
Number
Get the volume of this shape
Returns:
Properties
boundingSphereRadius
Number
The local bounding sphere radius of this shape.
collisionResponse
Boolean
Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.
data
Array
An array of numbers, or height values, that are spread out along the x axis.
elementSize
Number
The width of each element
id
Number
Identifyer of the Shape.
maxValue
Number
Max value of the data
minValue
Number
Max value of the data
type
Number
The type of this shape. Must be set to an int > 0 by subclasses.