Try to fix #2522 for a puck.
This commit is contained in:
parent
0a883f3832
commit
7a95f10cc0
@ -17,6 +17,10 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/CollisionShapes/btConvexShape.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
||||
#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
#include "BulletCollision/CollisionShapes/btTriangleShape.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
|
||||
|
||||
|
||||
@ -441,6 +445,32 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
|
||||
m_cachedSeparatingAxis = normalInB;
|
||||
m_cachedSeparatingDistance = distance;
|
||||
|
||||
// In some cases the normalInB is incorrect with a static triangle
|
||||
// mesh (i.e. it's the connection point between puck and triangle, not
|
||||
// the normal from the triangle - which is fine if the triangle mesh
|
||||
// is a dynamic rigid body (i.e. can be pushed away), but appears to
|
||||
// be wrong in case of a static body - it causes #2522 (puck suddenly
|
||||
// pushed in air). So in case of a static triangle mesh, recompute
|
||||
// the normal just based on the triangle mesh:
|
||||
const btManifoldResult *mani = dynamic_cast<btManifoldResult*>(&output);
|
||||
if(mani)
|
||||
{
|
||||
// Find the triangle:
|
||||
const btCollisionObject *b = mani->getBody0Internal();
|
||||
const btTriangleShape *tri = dynamic_cast<const btTriangleShape*>(b->getCollisionShape());
|
||||
if(!tri)
|
||||
{
|
||||
b = mani->getBody1Internal();
|
||||
tri = dynamic_cast<const btTriangleShape*>(b->getCollisionShape());
|
||||
}
|
||||
// If we have a triangle and it is static (mass=0), recompute the normal
|
||||
if(tri && btRigidBody::upcast(b)->getInvMass()==0)
|
||||
{
|
||||
normalInB = (tri->m_vertices1[1]-tri->m_vertices1[0])
|
||||
.cross(tri->m_vertices1[2]-tri->m_vertices1[0]);
|
||||
normalInB.normalize();;
|
||||
}
|
||||
}
|
||||
output.addContactPoint(
|
||||
normalInB,
|
||||
pointOnB+positionOffset,
|
||||
|
Loading…
Reference in New Issue
Block a user