mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 23:45:34 +00:00
Avoid heightfield conversion in newer Bullet
Takes advantage of the direct `float` support implemented in https://github.com/bulletphysics/bullet3/pull/3293
This commit is contained in:
parent
36d5d1c25c
commit
351d11449b
2 changed files with 16 additions and 0 deletions
|
@ -10,6 +10,12 @@
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
#if BT_BULLET_VERSION < 310
|
||||||
|
// Older Bullet versions only support `btScalar` heightfields.
|
||||||
|
// Our heightfield data is `float`.
|
||||||
|
//
|
||||||
|
// These functions handle conversion from `float` to `double` when
|
||||||
|
// `btScalar` is `double` (`BT_USE_DOUBLE_PRECISION`).
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -40,14 +46,18 @@ namespace
|
||||||
return btScalarHeights.data();
|
return btScalarHeights.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace MWPhysics
|
namespace MWPhysics
|
||||||
{
|
{
|
||||||
HeightField::HeightField(const float* heights, int x, int y, float triSize, float sqrtVerts, float minH, float maxH, const osg::Object* holdObject, PhysicsTaskScheduler* scheduler)
|
HeightField::HeightField(const float* heights, int x, int y, float triSize, float sqrtVerts, float minH, float maxH, const osg::Object* holdObject, PhysicsTaskScheduler* scheduler)
|
||||||
: mHoldObject(holdObject)
|
: mHoldObject(holdObject)
|
||||||
|
#if BT_BULLET_VERSION < 310
|
||||||
, mHeights(makeHeights(heights, sqrtVerts))
|
, mHeights(makeHeights(heights, sqrtVerts))
|
||||||
|
#endif
|
||||||
, mTaskScheduler(scheduler)
|
, mTaskScheduler(scheduler)
|
||||||
{
|
{
|
||||||
|
#if BT_BULLET_VERSION < 310
|
||||||
mShape = std::make_unique<btHeightfieldTerrainShape>(
|
mShape = std::make_unique<btHeightfieldTerrainShape>(
|
||||||
sqrtVerts, sqrtVerts,
|
sqrtVerts, sqrtVerts,
|
||||||
getHeights(heights, mHeights),
|
getHeights(heights, mHeights),
|
||||||
|
@ -55,6 +65,10 @@ namespace MWPhysics
|
||||||
minH, maxH, 2,
|
minH, maxH, 2,
|
||||||
PHY_FLOAT, false
|
PHY_FLOAT, false
|
||||||
);
|
);
|
||||||
|
#else
|
||||||
|
mShape = std::make_unique<btHeightfieldTerrainShape>(
|
||||||
|
sqrtVerts, sqrtVerts, heights, minH, maxH, 2, false);
|
||||||
|
#endif
|
||||||
mShape->setUseDiamondSubdivision(true);
|
mShape->setUseDiamondSubdivision(true);
|
||||||
mShape->setLocalScaling(btVector3(triSize, triSize, 1));
|
mShape->setLocalScaling(btVector3(triSize, triSize, 1));
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,9 @@ namespace MWPhysics
|
||||||
std::unique_ptr<btHeightfieldTerrainShape> mShape;
|
std::unique_ptr<btHeightfieldTerrainShape> mShape;
|
||||||
std::unique_ptr<btCollisionObject> mCollisionObject;
|
std::unique_ptr<btCollisionObject> mCollisionObject;
|
||||||
osg::ref_ptr<const osg::Object> mHoldObject;
|
osg::ref_ptr<const osg::Object> mHoldObject;
|
||||||
|
#if BT_BULLET_VERSION < 310
|
||||||
std::vector<btScalar> mHeights;
|
std::vector<btScalar> mHeights;
|
||||||
|
#endif
|
||||||
|
|
||||||
PhysicsTaskScheduler* mTaskScheduler;
|
PhysicsTaskScheduler* mTaskScheduler;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue