Heightfield class
Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a given distance. @todo Should be possible to use along all axes, not just y @todo should be possible to scale along all axes @todo Refactor elementSize to elementSizeX and elementSizeY
@example // Generate some height data (y-values). final data = [] for (let i = 0; i < 1000; i++) { final y = 0.5 * Math.cos(0.2 * i) data.add(y) }
// Create the heightfield shape
final heightfieldShape = CANNON.Heightfield(data, {
elementSize: 1 // Distance between the data points in X and Y directions
})
final heightfieldBody = CANNON.Body({ shape: heightfieldShape })
world.addBody(heightfieldBody)
Constructors
Properties
- body ↔ Body?
-
The body to which the shape is added to.
getter/setter pairinherited
- boundingSphereRadius ↔ double
-
The local bounding sphere radius of this shape.
getter/setter pairinherited
- cacheEnabled ↔ bool
-
getter/setter pair
- collisionFilterGroup ↔ int
-
getter/setter pairinherited
- collisionFilterMask ↔ int
-
getter/setter pairinherited
- collisionResponse ↔ bool
-
Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.
getter/setter pairinherited
-
data
↔ List<
List< double> > -
An array of numbers, or height values, that are spread out along the x axis.
getter/setter pair
- elementSize ↔ int
-
World spacing between the data points in X and Y direction.
@todo elementSizeX and Y
getter/setter pair
-
getHeightAtIdx
↔ List<
int> -
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- id ↔ int
-
Identifier of the Shape.
getter/setter pairinherited
- material ↔ Material?
-
Optional material of the shape that regulates contact properties.
getter/setter pairinherited
- maxValue ↔ double?
-
Max value of the data points in the data array.
getter/setter pair
- minValue ↔ double?
-
Minimum value of the data points in the data array.
getter/setter pair
- pillarConvex ↔ ConvexPolyhedron
-
getter/setter pair
- pillarOffset ↔ Vec3
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- segments ↔ Size
-
getter/setter pair
- size ↔ Size
-
getter/setter pair
- type ↔ ShapeType
-
The type of this shape. Must be set to an int > 0 by subclasses.
getter/setter pairinherited
Methods
-
barycentricWeights(
double x, double y, double ax, double ay, double bx, double by, double cx, double cy, Vec3 result) → void -
calculateLocalInertia(
double mass, [Vec3? target]) → Vec3 -
Calculates the inertia in the local frame for this shape.
@see http://en.wikipedia.org/wiki/List_of_moments_of_inertia
override
-
calculateWorldAABB(
Vec3 pos, Quaternion quat, Vec3 min, Vec3 max) → void -
@todo use abstract for these kind of methods
override
-
clearCachedConvexTrianglePillar(
int xi, int yi, bool getUpperTriangle) → void -
getAabbAtIndex(
int xi, int yi, AABB aabb) → void - Get an AABB of a square in the heightfield @param xi @param yi @param result
-
getCacheConvexTrianglePillarKey(
int xi, int yi, bool getUpperTriangle) → String -
getCachedConvexTrianglePillar(
int xi, int yi, bool getUpperTriangle) → HeightfieldPillar? -
getConvexTrianglePillar(
int xi, int yi, bool getUpperTriangle) → void - Get a triangle in the terrain in the form of a triangular convex shape.
-
getHeightAt(
double x, double y, bool edgeClamp) → double - Get the height in the heightfield at a given position
-
getIndexOfPosition(
double x, double y, List< int> result, bool clamp) → bool - 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. @param result Two-element array @param clamp If the position should be clamped to the heightfield edge.
-
getNormalAt(
double x, double y, bool edgeClamp, Vec3 result) → void -
getRectMinMax(
int iMinX, int iMinY, int iMaxX, int iMaxY, List< double> result) → void - Get max/min in a rectangle in the matrix data @param result An array to store the results in. @return The result array, if it was passed in. Minimum will be at position 0 and max at 1.
-
getTriangle(
int xi, int yi, bool upper, Vec3 a, Vec3 b, Vec3 c) → void - Get a triangle from the heightfield
-
getTriangleAt(
double x, double y, bool edgeClamp, Vec3 a, Vec3 b, Vec3 c) → bool -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setCachedConvexTrianglePillar(
int xi, int yi, bool getUpperTriangle, ConvexPolyhedron convex, Vec3 offset) → void -
setHeightsFromImage(
Image image, Vec3 scale) → void - Sets the height values from an image. Currently only supported in browser.
-
setHeightValueAtIndex(
int xi, int yi, double value) → void - Set the height value at an index. Don't forget to update maxValue and minValue after you're done.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
) → void - Call whenever you change the data array.
-
updateBoundingSphereRadius(
) → void -
Computes the bounding sphere radius.
The result is stored in the property
.boundingSphereRadius
override -
updateMaxValue(
) → void -
Update the
maxValue
property -
updateMinValue(
) → void -
Update the
minValue
property -
volume(
) → double -
Get the volume of this shape
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited