Height field terrain shape fixes from tomva1@yahoo.com
This commit is contained in:
@@ -144,7 +144,12 @@ void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,
|
|||||||
aabbMax = center + extent;
|
aabbMax = center + extent;
|
||||||
}
|
}
|
||||||
|
|
||||||
btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const
|
|
||||||
|
/// This returns the "raw" (user's initial) height, not the actual height.
|
||||||
|
/// The actual height needs to be adjusted to be relative to the center
|
||||||
|
/// of the heightfield's AABB.
|
||||||
|
btScalar
|
||||||
|
btHeightfieldTerrainShape::getRawHeightFieldValue(int x,int y) const
|
||||||
{
|
{
|
||||||
btScalar val = 0.f;
|
btScalar val = 0.f;
|
||||||
switch (m_heightDataType)
|
switch (m_heightDataType)
|
||||||
@@ -181,24 +186,22 @@ btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// this returns the vertex in bullet-local coordinates
|
||||||
void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
|
void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
|
||||||
{
|
{
|
||||||
|
|
||||||
btAssert(x>=0);
|
btAssert(x>=0);
|
||||||
btAssert(y>=0);
|
btAssert(y>=0);
|
||||||
btAssert(x<m_heightStickWidth);
|
btAssert(x<m_heightStickWidth);
|
||||||
btAssert(y<m_heightStickLength);
|
btAssert(y<m_heightStickLength);
|
||||||
|
|
||||||
|
btScalar height = getRawHeightFieldValue(x,y);
|
||||||
btScalar height = getHeightFieldValue(x,y);
|
|
||||||
|
|
||||||
switch (m_upAxis)
|
switch (m_upAxis)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
vertex.setValue(
|
vertex.setValue(
|
||||||
height,
|
height - m_localOrigin.getX(),
|
||||||
(-m_width/btScalar(2.0)) + x,
|
(-m_width/btScalar(2.0)) + x,
|
||||||
(-m_length/btScalar(2.0) ) + y
|
(-m_length/btScalar(2.0) ) + y
|
||||||
);
|
);
|
||||||
@@ -208,7 +211,7 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
|
|||||||
{
|
{
|
||||||
vertex.setValue(
|
vertex.setValue(
|
||||||
(-m_width/btScalar(2.0)) + x,
|
(-m_width/btScalar(2.0)) + x,
|
||||||
height,
|
height - m_localOrigin.getY(),
|
||||||
(-m_length/btScalar(2.0)) + y
|
(-m_length/btScalar(2.0)) + y
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@@ -218,7 +221,7 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
|
|||||||
vertex.setValue(
|
vertex.setValue(
|
||||||
(-m_width/btScalar(2.0)) + x,
|
(-m_width/btScalar(2.0)) + x,
|
||||||
(-m_length/btScalar(2.0)) + y,
|
(-m_length/btScalar(2.0)) + y,
|
||||||
height
|
height - m_localOrigin.getZ()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -230,7 +233,6 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
vertex*=m_localScaling;
|
vertex*=m_localScaling;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,17 @@ subject to the following restrictions:
|
|||||||
center (as determined by width and length and height, with each
|
center (as determined by width and length and height, with each
|
||||||
axis multiplied by the localScaling).
|
axis multiplied by the localScaling).
|
||||||
|
|
||||||
|
\b NOTE: be careful with coordinates. If you have a heightfield with a local
|
||||||
|
min height of -100m, and a max height of +500m, you may be tempted to place it
|
||||||
|
at the origin (0,0) and expect the heights in world coordinates to be
|
||||||
|
-100 to +500 meters.
|
||||||
|
Actually, the heights will be -300 to +300m, because bullet will re-center
|
||||||
|
the heightfield based on its AABB (which is determined by the min/max
|
||||||
|
heights). So keep in mind that once you create a btHeightfieldTerrainShape
|
||||||
|
object, the heights will be adjusted relative to the center of the AABB. This
|
||||||
|
is different to the behavior of many rendering engines, but is useful for
|
||||||
|
physics engines.
|
||||||
|
|
||||||
Most (but not all) rendering and heightfield libraries assume upAxis = 1
|
Most (but not all) rendering and heightfield libraries assume upAxis = 1
|
||||||
(that is, the y-axis is "up"). This class allows any of the 3 coordinates
|
(that is, the y-axis is "up"). This class allows any of the 3 coordinates
|
||||||
to be "up". Make sure your choice of axis is consistent with your rendering
|
to be "up". Make sure your choice of axis is consistent with your rendering
|
||||||
@@ -88,7 +99,7 @@ protected:
|
|||||||
|
|
||||||
btVector3 m_localScaling;
|
btVector3 m_localScaling;
|
||||||
|
|
||||||
virtual btScalar getHeightFieldValue(int x,int y) const;
|
virtual btScalar getRawHeightFieldValue(int x,int y) const;
|
||||||
void quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
|
void quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
|
||||||
void getVertex(int x,int y,btVector3& vertex) const;
|
void getVertex(int x,int y,btVector3& vertex) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user