Jolt Physics
A multi core friendly Game Physics Engine
|
Class that constructs a HeightFieldShape. More...
#include <HeightFieldShape.h>
Public Attributes | |
Vec3 | mOffset = Vec3::sZero() |
Vec3 | mScale = Vec3::sReplicate(1.0f) |
uint32 | mSampleCount = 0 |
float | mMinHeightValue = FLT_MAX |
Artificial minimal value of mHeightSamples, used for compression and can be used to update the terrain after creating with lower height values. If there are any lower values in mHeightSamples, this value will be ignored. | |
float | mMaxHeightValue = -FLT_MAX |
Artificial maximum value of mHeightSamples, used for compression and can be used to update the terrain after creating with higher height values. If there are any higher values in mHeightSamples, this value will be ignored. | |
uint32 | mBlockSize = 2 |
uint32 | mBitsPerSample = 8 |
Array< float > | mHeightSamples |
An array of mSampleCount^2 height samples. Samples are stored in row major order, so the sample at (x, y) is at index y * mSampleCount + x. | |
Array< uint8 > | mMaterialIndices |
An array of (mSampleCount - 1)^2 material indices. | |
PhysicsMaterialList | mMaterials |
The materials of square at (x, y) is: mMaterials[mMaterialIndices[x + y * (mSampleCount - 1)]]. | |
float | mActiveEdgeCosThresholdAngle = 0.996195f |
Public Attributes inherited from ShapeSettings | |
uint64 | mUserData = 0 |
User data (to be used freely by the application) | |
Additional Inherited Members | |
Public Types inherited from ShapeSettings | |
using | ShapeResult = Result<Ref<Shape>> |
Static Public Member Functions inherited from RefTarget< ShapeSettings > | |
static int | sInternalGetRefCountOffset () |
INTERNAL HELPER FUNCTION USED BY SERIALIZATION. | |
Protected Attributes inherited from ShapeSettings | |
ShapeResult | mCachedResult |
Protected Attributes inherited from RefTarget< ShapeSettings > | |
atomic< uint32 > | mRefCount |
Current reference count. | |
Static Protected Attributes inherited from RefTarget< ShapeSettings > | |
static constexpr uint32 | cEmbedded |
A large value that gets added to the refcount to mark the object as embedded. | |
Class that constructs a HeightFieldShape.
|
default |
Default constructor for deserialization.
HeightFieldShapeSettings::HeightFieldShapeSettings | ( | const float * | inSamples, |
Vec3Arg | inOffset, | ||
Vec3Arg | inScale, | ||
uint32 | inSampleCount, | ||
const uint8 * | inMaterialIndices = nullptr, | ||
const PhysicsMaterialList & | inMaterialList = PhysicsMaterialList() ) |
Create a height field shape of inSampleCount * inSampleCount vertices. The height field is a surface defined by: inOffset + inScale * (x, inSamples[y * inSampleCount + x], y). where x and y are integers in the range x and y e [0, inSampleCount - 1]. inSampleCount: inSampleCount / mBlockSize must be minimally 2 and a power of 2 is the most efficient in terms of performance and storage. inSamples: inSampleCount^2 vertices. inMaterialIndices: (inSampleCount - 1)^2 indices that index into inMaterialList.
Given mBlockSize, mSampleCount and mHeightSamples, calculate the amount of bits needed to stay below absolute error inMaxError
inMaxError | Maximum allowed error in mHeightSamples after compression (note that this does not take mScale.Y into account) |
|
overridevirtual |
Create a shape according to the settings specified by this object.
Implements ShapeSettings.
void HeightFieldShapeSettings::DetermineMinAndMaxSample | ( | float & | outMinValue, |
float & | outMaxValue, | ||
float & | outQuantizationScale ) const |
Determine the minimal and maximal value of mHeightSamples (will ignore cNoCollisionValue)
outMinValue | The minimal value of mHeightSamples or FLT_MAX if no samples have collision |
outMaxValue | The maximal value of mHeightSamples or -FLT_MAX if no samples have collision |
outQuantizationScale | (value - outMinValue) * outQuantizationScale quantizes a height sample to 16 bits |
float HeightFieldShapeSettings::mActiveEdgeCosThresholdAngle = 0.996195f |
Cosine of the threshold angle (if the angle between the two triangles is bigger than this, the edge is active, note that a concave edge is always inactive). Setting this value too small can cause ghost collisions with edges, setting it too big can cause depenetration artifacts (objects not depenetrating quickly). Valid ranges are between cos(0 degrees) and cos(90 degrees). The default value is cos(5 degrees).
uint32 HeightFieldShapeSettings::mBitsPerSample = 8 |
How many bits per sample to use to compress the height field. Can be in the range [1, 8]. Note that each sample is compressed relative to the min/max value of its block of mBlockSize * mBlockSize pixels so the effective precision is higher. Also note that increasing mBlockSize saves more memory than reducing the amount of bits per sample.
uint32 HeightFieldShapeSettings::mBlockSize = 2 |
The heightfield is divided in blocks of mBlockSize * mBlockSize * 2 triangles and the acceleration structure culls blocks only, bigger block sizes reduce memory consumption but also reduce query performance. Sensible values are [2, 8], does not need to be a power of 2. Note that at run-time we'll perform one more grid subdivision, so the effective block size is half of what is provided here.
An array of mSampleCount^2 height samples. Samples are stored in row major order, so the sample at (x, y) is at index y * mSampleCount + x.
An array of (mSampleCount - 1)^2 material indices.
PhysicsMaterialList HeightFieldShapeSettings::mMaterials |
The materials of square at (x, y) is: mMaterials[mMaterialIndices[x + y * (mSampleCount - 1)]].
Artificial maximum value of mHeightSamples, used for compression and can be used to update the terrain after creating with higher height values. If there are any higher values in mHeightSamples, this value will be ignored.
Artificial minimal value of mHeightSamples, used for compression and can be used to update the terrain after creating with lower height values. If there are any lower values in mHeightSamples, this value will be ignored.
Vec3 HeightFieldShapeSettings::mOffset = Vec3::sZero() |
The height field is a surface defined by: mOffset + mScale * (x, mHeightSamples[y * mSampleCount + x], y). where x and y are integers in the range x and y e [0, mSampleCount - 1].
uint32 HeightFieldShapeSettings::mSampleCount = 0 |
Vec3 HeightFieldShapeSettings::mScale = Vec3::sReplicate(1.0f) |