mirror of
https://github.com/OpenMW/openmw.git
synced 2025-05-10 04:11:25 +00:00
Support bullet with double precision
This commit is contained in:
parent
ef5a5ef43f
commit
2d7c3bae61
4 changed files with 77 additions and 6 deletions
|
@ -7,12 +7,48 @@
|
||||||
|
|
||||||
#include <LinearMath/btTransform.h>
|
#include <LinearMath/btTransform.h>
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
auto makeHeights(const T* heights, float sqrtVerts)
|
||||||
|
-> std::enable_if_t<std::is_same<btScalar, T>::value, std::vector<btScalar>>
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
auto makeHeights(const T* heights, float sqrtVerts)
|
||||||
|
-> std::enable_if_t<!std::is_same<btScalar, T>::value, std::vector<btScalar>>
|
||||||
|
{
|
||||||
|
return std::vector<btScalar>(heights, heights + static_cast<std::ptrdiff_t>(sqrtVerts * sqrtVerts));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
auto getHeights(const T* floatHeights, const std::vector<btScalar>&)
|
||||||
|
-> std::enable_if_t<std::is_same<btScalar, T>::value, const btScalar*>
|
||||||
|
{
|
||||||
|
return floatHeights;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
auto getHeights(const T*, const std::vector<btScalar>& btScalarHeights)
|
||||||
|
-> std::enable_if_t<!std::is_same<btScalar, T>::value, const btScalar*>
|
||||||
|
{
|
||||||
|
return btScalarHeights.data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
HeightField::HeightField(const float* heights, int x, int y, float triSize, float sqrtVerts, float minH, float maxH, const osg::Object* holdObject)
|
||||||
|
: mHeights(makeHeights(heights, sqrtVerts))
|
||||||
{
|
{
|
||||||
mShape = new btHeightfieldTerrainShape(
|
mShape = new btHeightfieldTerrainShape(
|
||||||
sqrtVerts, sqrtVerts, heights, 1,
|
sqrtVerts, sqrtVerts,
|
||||||
|
getHeights(heights, mHeights),
|
||||||
|
1,
|
||||||
minH, maxH, 2,
|
minH, maxH, 2,
|
||||||
PHY_FLOAT, false
|
PHY_FLOAT, false
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
#include <osg/ref_ptr>
|
#include <osg/ref_ptr>
|
||||||
|
|
||||||
|
#include <LinearMath/btScalar.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class btCollisionObject;
|
class btCollisionObject;
|
||||||
class btHeightfieldTerrainShape;
|
class btHeightfieldTerrainShape;
|
||||||
|
|
||||||
|
@ -27,6 +31,7 @@ namespace MWPhysics
|
||||||
btHeightfieldTerrainShape* mShape;
|
btHeightfieldTerrainShape* mShape;
|
||||||
btCollisionObject* mCollisionObject;
|
btCollisionObject* mCollisionObject;
|
||||||
osg::ref_ptr<const osg::Object> mHoldObject;
|
osg::ref_ptr<const osg::Object> mHoldObject;
|
||||||
|
std::vector<btScalar> mHeights;
|
||||||
|
|
||||||
void operator=(const HeightField&);
|
void operator=(const HeightField&);
|
||||||
HeightField(const HeightField&);
|
HeightField(const HeightField&);
|
||||||
|
|
|
@ -363,11 +363,11 @@ namespace
|
||||||
AreaType_ground
|
AreaType_ground
|
||||||
);
|
);
|
||||||
const auto recastMesh = builder.create(mGeneration, mRevision);
|
const auto recastMesh = builder.create(mGeneration, mRevision);
|
||||||
EXPECT_EQ(recastMesh->getVertices(), std::vector<float>({
|
EXPECT_THAT(recastMesh->getVertices(), Pointwise(FloatNear(1e-5), std::vector<float>({
|
||||||
1.41421353816986083984375, 0, 1.1920928955078125e-07,
|
1.41421353816986083984375, 0, 1.1920928955078125e-07,
|
||||||
-1.41421353816986083984375, 0, -1.1920928955078125e-07,
|
-1.41421353816986083984375, 0, -1.1920928955078125e-07,
|
||||||
1.1920928955078125e-07, 0, -1.41421353816986083984375,
|
1.1920928955078125e-07, 0, -1.41421353816986083984375,
|
||||||
}));
|
})));
|
||||||
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
EXPECT_EQ(recastMesh->getIndices(), std::vector<int>({0, 1, 2}));
|
||||||
EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
EXPECT_EQ(recastMesh->getAreaTypes(), std::vector<AreaType>({AreaType_ground}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -30,6 +32,34 @@ namespace
|
||||||
shape.processAllTriangles(&callback, aabbMin, aabbMax);
|
shape.processAllTriangles(&callback, aabbMin, aabbMax);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isNear(btScalar lhs, btScalar rhs)
|
||||||
|
{
|
||||||
|
return std::abs(lhs - rhs) <= 1e-5;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNear(const btVector3& lhs, const btVector3& rhs)
|
||||||
|
{
|
||||||
|
return std::equal(
|
||||||
|
static_cast<const btScalar*>(lhs),
|
||||||
|
static_cast<const btScalar*>(lhs) + 3,
|
||||||
|
static_cast<const btScalar*>(rhs),
|
||||||
|
[] (btScalar lhs, btScalar rhs) { return isNear(lhs, rhs); }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNear(const btMatrix3x3& lhs, const btMatrix3x3& rhs)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; ++i)
|
||||||
|
if (!isNear(lhs[i], rhs[i]))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isNear(const btTransform& lhs, const btTransform& rhs)
|
||||||
|
{
|
||||||
|
return isNear(lhs.getOrigin(), rhs.getOrigin()) && isNear(lhs.getBasis(), rhs.getBasis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::ostream& operator <<(std::ostream& stream, const btVector3& value)
|
static std::ostream& operator <<(std::ostream& stream, const btVector3& value)
|
||||||
|
@ -157,7 +187,7 @@ static bool operator ==(const btCompoundShape& lhs, const btCompoundShape& rhs)
|
||||||
for (int i = 0; i < lhs.getNumChildShapes(); ++i)
|
for (int i = 0; i < lhs.getNumChildShapes(); ++i)
|
||||||
{
|
{
|
||||||
if (!compareObjects(lhs.getChildShape(i), rhs.getChildShape(i))
|
if (!compareObjects(lhs.getChildShape(i), rhs.getChildShape(i))
|
||||||
|| !(lhs.getChildTransform(i) == rhs.getChildTransform(i)))
|
|| !isNear(lhs.getChildTransform(i), rhs.getChildTransform(i)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -165,13 +195,13 @@ static bool operator ==(const btCompoundShape& lhs, const btCompoundShape& rhs)
|
||||||
|
|
||||||
static bool operator ==(const btBoxShape& lhs, const btBoxShape& rhs)
|
static bool operator ==(const btBoxShape& lhs, const btBoxShape& rhs)
|
||||||
{
|
{
|
||||||
return lhs.getLocalScaling() == rhs.getLocalScaling()
|
return isNear(lhs.getLocalScaling(), rhs.getLocalScaling())
|
||||||
&& lhs.getHalfExtentsWithoutMargin() == rhs.getHalfExtentsWithoutMargin();
|
&& lhs.getHalfExtentsWithoutMargin() == rhs.getHalfExtentsWithoutMargin();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool operator ==(const btBvhTriangleMeshShape& lhs, const btBvhTriangleMeshShape& rhs)
|
static bool operator ==(const btBvhTriangleMeshShape& lhs, const btBvhTriangleMeshShape& rhs)
|
||||||
{
|
{
|
||||||
return lhs.getLocalScaling() == rhs.getLocalScaling()
|
return isNear(lhs.getLocalScaling(), rhs.getLocalScaling())
|
||||||
&& lhs.usesQuantizedAabbCompression() == rhs.usesQuantizedAabbCompression()
|
&& lhs.usesQuantizedAabbCompression() == rhs.usesQuantizedAabbCompression()
|
||||||
&& lhs.getOwnsBvh() == rhs.getOwnsBvh()
|
&& lhs.getOwnsBvh() == rhs.getOwnsBvh()
|
||||||
&& getTriangles(lhs) == getTriangles(rhs);
|
&& getTriangles(lhs) == getTriangles(rhs);
|
||||||
|
|
Loading…
Reference in a new issue