mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +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
@ -10,6 +10,12 @@
|
||||
|
||||
#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
|
||||
{
|
||||
template <class T>
|
||||
@ -40,14 +46,18 @@ namespace
|
||||
return btScalarHeights.data();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
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)
|
||||
: mHoldObject(holdObject)
|
||||
#if BT_BULLET_VERSION < 310
|
||||
, mHeights(makeHeights(heights, sqrtVerts))
|
||||
#endif
|
||||
, mTaskScheduler(scheduler)
|
||||
{
|
||||
#if BT_BULLET_VERSION < 310
|
||||
mShape = std::make_unique<btHeightfieldTerrainShape>(
|
||||
sqrtVerts, sqrtVerts,
|
||||
getHeights(heights, mHeights),
|
||||
@ -55,6 +65,10 @@ namespace MWPhysics
|
||||
minH, maxH, 2,
|
||||
PHY_FLOAT, false
|
||||
);
|
||||
#else
|
||||
mShape = std::make_unique<btHeightfieldTerrainShape>(
|
||||
sqrtVerts, sqrtVerts, heights, minH, maxH, 2, false);
|
||||
#endif
|
||||
mShape->setUseDiamondSubdivision(true);
|
||||
mShape->setLocalScaling(btVector3(triSize, triSize, 1));
|
||||
|
||||
|
@ -34,7 +34,9 @@ namespace MWPhysics
|
||||
std::unique_ptr<btHeightfieldTerrainShape> mShape;
|
||||
std::unique_ptr<btCollisionObject> mCollisionObject;
|
||||
osg::ref_ptr<const osg::Object> mHoldObject;
|
||||
#if BT_BULLET_VERSION < 310
|
||||
std::vector<btScalar> mHeights;
|
||||
#endif
|
||||
|
||||
PhysicsTaskScheduler* mTaskScheduler;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user