From 114bfad68f53ee3a99103d7402c854dc9d7b8e2d Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Thu, 28 Jun 2007 20:40:54 +0000 Subject: [PATCH] made some improvements based on feedback. - made getHeightFieldValue virtual (allows custom heightfield formats) - don't use shorts, just full integers (no reason to limit the terrain size to 65536) --- .../CollisionShapes/btHeightfieldTerrainShape.cpp | 15 +++++++-------- .../CollisionShapes/btHeightfieldTerrainShape.h | 10 ++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp index 184234648..f3ba1480a 100644 --- a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp +++ b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp @@ -77,8 +77,6 @@ m_flipQuadEdges(flipQuadEdges) m_localAabbMax = halfExtents + clampValue; btVector3 aabbSize = m_localAabbMax - m_localAabbMin; - m_quantization = btVector3(btScalar(65535.0),btScalar(65535.0),btScalar(65535.0)) / aabbSize; - } @@ -118,6 +116,7 @@ btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const val = m_heightfieldDataFloat[(y*m_width)+x]; } else { + //assume unsigned short int unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_width)+x]; val = heightFieldValue* (m_maxHeight/btScalar(65535)); } @@ -180,7 +179,7 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const } -void btHeightfieldTerrainShape::quantizeWithClamp(short* out, const btVector3& point) const +void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point) const { @@ -190,9 +189,9 @@ void btHeightfieldTerrainShape::quantizeWithClamp(short* out, const btVector3& p btVector3 v = (clampedPoint );// * m_quantization; - out[0] = (short)(v.getX()); - out[1] = (short)(v.getY()); - out[2] = (short)(v.getZ()); + out[0] = (int)(v.getX()); + out[1] = (int)(v.getY()); + out[2] = (int)(v.getZ()); //correct for } @@ -206,8 +205,8 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback //quantize the aabbMin and aabbMax, and adjust the start/end ranges - short quantizedAabbMin[3]; - short quantizedAabbMax[3]; + int quantizedAabbMin[3]; + int quantizedAabbMax[3]; btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]); btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]); diff --git a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h index 1b0ab994c..cc0590e5d 100644 --- a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h +++ b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h @@ -32,7 +32,7 @@ protected: union { unsigned char* m_heightfieldDataUnsignedChar; - float* m_heightfieldDataFloat; + btScalar* m_heightfieldDataFloat; void* m_heightfieldDataUnknown; }; @@ -41,15 +41,13 @@ protected: int m_upAxis; - btVector3 m_quantization; - btVector3 m_localScaling; - btScalar getHeightFieldValue(int x,int y) const; - void quantizeWithClamp(short* out, const btVector3& point) const; + virtual btScalar getHeightFieldValue(int x,int y) const; + void quantizeWithClamp(int* 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(int* aabbMin1, int* aabbMax1,const int* aabbMin2,const int* aabbMax2) const { bool overlap = true; overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;