allow for float data, and prepare for 'quad edge flip', either re-use the first triangle vertex, or second (re-use index 00 or 01)

This commit is contained in:
ejcoumans
2007-06-27 19:56:18 +00:00
parent 9099d6bed5
commit cad28a8b35
3 changed files with 43 additions and 12 deletions

View File

@@ -237,7 +237,10 @@ const float TRIANGLE_SIZE=20.f;
btScalar maxHeight = 20000.f; btScalar maxHeight = 20000.f;
groundShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex); bool useFloatDatam=false;
bool flipQuadEdges=false;
groundShape = new btHeightfieldTerrainShape(width,length,heightfieldData,maxHeight,upIndex,useFloatDatam,flipQuadEdges);
btVector3 localScaling(20,20,20); btVector3 localScaling(20,20,20);
localScaling[upIndex]=1.f; localScaling[upIndex]=1.f;
groundShape->setLocalScaling(localScaling); groundShape->setLocalScaling(localScaling);

View File

@@ -18,13 +18,15 @@ subject to the following restrictions:
#include "LinearMath/btTransformUtil.h" #include "LinearMath/btTransformUtil.h"
btHeightfieldTerrainShape::btHeightfieldTerrainShape(int width,int length,unsigned char* heightfieldData,btScalar maxHeight,int upAxis) btHeightfieldTerrainShape::btHeightfieldTerrainShape(int width,int length,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
:m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), :m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
m_width(width), m_width(width),
m_length(length), m_length(length),
m_heightfieldData(heightfieldData), m_heightfieldDataUnknown(heightfieldData),
m_maxHeight(maxHeight), m_maxHeight(maxHeight),
m_upAxis(upAxis) m_upAxis(upAxis),
m_useFloatData(useFloatData),
m_flipQuadEdges(flipQuadEdges)
{ {
@@ -108,6 +110,21 @@ void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,
} }
btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const
{
btScalar val = 0.f;
if (m_useFloatData)
{
btScalar val = m_heightfieldDataFloat[(y*m_width)+x];
} else
{
unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_width)+x];
btScalar val = heightFieldValue* (m_maxHeight/btScalar(65535));
}
return val;
}
@@ -119,14 +136,15 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
btAssert(x<m_width); btAssert(x<m_width);
btAssert(y<m_length); btAssert(y<m_length);
unsigned char heightFieldValue = m_heightfieldData[(y*m_width)+x];
btScalar height = getHeightFieldValue(x,y);
switch (m_upAxis) switch (m_upAxis)
{ {
case 0: case 0:
{ {
vertex.setValue( vertex.setValue(
heightFieldValue* (m_maxHeight/btScalar(65535)), height,
(-m_width/2 ) + x, (-m_width/2 ) + x,
(-m_length/2 ) + y (-m_length/2 ) + y
); );
@@ -136,7 +154,7 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
{ {
vertex.setValue( vertex.setValue(
(-m_width/2 ) + x, (-m_width/2 ) + x,
heightFieldValue* (m_maxHeight/btScalar(65535)), height,
(-m_length/2 ) + y (-m_length/2 ) + y
); );
break; break;
@@ -146,7 +164,7 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
vertex.setValue( vertex.setValue(
(-m_width/2 ) + x, (-m_width/2 ) + x,
(-m_length/2 ) + y, (-m_length/2 ) + y,
heightFieldValue* (m_maxHeight/btScalar(65535)) height
); );
break; break;
} }

View File

@@ -29,15 +29,25 @@ protected:
int m_width; int m_width;
int m_length; int m_length;
btScalar m_maxHeight; btScalar m_maxHeight;
unsigned char* m_heightfieldData; union
{
unsigned char* m_heightfieldDataUnsignedChar;
float* m_heightfieldDataFloat;
void* m_heightfieldDataUnknown;
};
bool m_useFloatData;
bool m_flipQuadEdges;
int m_upAxis; int m_upAxis;
btVector3 m_quantization; btVector3 m_quantization;
btVector3 m_localScaling; btVector3 m_localScaling;
void quantizeWithClamp(short* out, const btVector3& point) const; btScalar getHeightFieldValue(int x,int y) const;
void getVertex(int x,int y,btVector3& vertex) const; void quantizeWithClamp(short* out, const btVector3& point) const;
void getVertex(int x,int y,btVector3& vertex) const;
inline bool testQuantizedAabbAgainstQuantizedAabb(short int* aabbMin1,short int* aabbMax1,const short int* aabbMin2,const short int* aabbMax2) const inline bool testQuantizedAabbAgainstQuantizedAabb(short int* aabbMin1,short int* aabbMax1,const short int* aabbMin2,const short int* aabbMax2) const
{ {
@@ -49,7 +59,7 @@ protected:
} }
public: public:
btHeightfieldTerrainShape(int width,int height,unsigned char* heightfieldData, btScalar maxHeight,int upAxis); btHeightfieldTerrainShape(int width,int height,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
virtual ~btHeightfieldTerrainShape(); virtual ~btHeightfieldTerrainShape();