Improved fix for 2522 by using isStaticOrKinematicObject() function

(instead of accessing the rigid body). This separates collision
and dynamic handling of bullet again.
This commit is contained in:
hiker 2016-06-27 07:48:30 +10:00
parent 0eb4ca2abd
commit 431ed63da2
2 changed files with 12 additions and 14 deletions

View File

@ -20,7 +20,6 @@ subject to the following restrictions:
#include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/CollisionDispatch/btManifoldResult.h" #include "BulletCollision/CollisionDispatch/btManifoldResult.h"
#include "BulletCollision/CollisionShapes/btTriangleShape.h" #include "BulletCollision/CollisionShapes/btTriangleShape.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
SphereTriangleDetector::SphereTriangleDetector(btSphereShape* sphere,btTriangleShape* triangle,btScalar contactBreakingThreshold) SphereTriangleDetector::SphereTriangleDetector(btSphereShape* sphere,btTriangleShape* triangle,btScalar contactBreakingThreshold)
@ -59,15 +58,15 @@ void SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input,Res
if(mani) if(mani)
{ {
// Find the triangle: // Find the triangle:
const btCollisionObject *b = mani->getBody0Internal(); const btCollisionObject *co = mani->getBody0Internal();
const btTriangleShape *tri = dynamic_cast<const btTriangleShape*>(b->getCollisionShape()); const btTriangleShape *tri = dynamic_cast<const btTriangleShape*>(co->getCollisionShape());
if(!tri) if(!tri)
{ {
b = mani->getBody1Internal(); co = mani->getBody1Internal();
tri = dynamic_cast<const btTriangleShape*>(b->getCollisionShape()); tri = dynamic_cast<const btTriangleShape*>(co->getCollisionShape());
} }
// If we have a triangle and it is static (mass=0), recompute the normal // If we have a triangle and it is static, recompute the normal
if(tri && btRigidBody::upcast(b)->getInvMass()==0) if(tri && co->isStaticOrKinematicObject())
{ {
normal = (tri->m_vertices1[1]-tri->m_vertices1[0]) normal = (tri->m_vertices1[1]-tri->m_vertices1[0])
.cross(tri->m_vertices1[2]-tri->m_vertices1[0]); .cross(tri->m_vertices1[2]-tri->m_vertices1[0]);

View File

@ -20,7 +20,6 @@ subject to the following restrictions:
#include "BulletCollision/CollisionDispatch/btManifoldResult.h" #include "BulletCollision/CollisionDispatch/btManifoldResult.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/CollisionShapes/btTriangleShape.h" #include "BulletCollision/CollisionShapes/btTriangleShape.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
@ -456,15 +455,15 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
if(mani) if(mani)
{ {
// Find the triangle: // Find the triangle:
const btCollisionObject *b = mani->getBody0Internal(); const btCollisionObject *co = mani->getBody0Internal();
const btTriangleShape *tri = dynamic_cast<const btTriangleShape*>(b->getCollisionShape()); const btTriangleShape *tri = dynamic_cast<const btTriangleShape*>(co->getCollisionShape());
if(!tri) if(!tri)
{ {
b = mani->getBody1Internal(); co = mani->getBody1Internal();
tri = dynamic_cast<const btTriangleShape*>(b->getCollisionShape()); tri = dynamic_cast<const btTriangleShape*>(co->getCollisionShape());
} }
// If we have a triangle and it is static (mass=0), recompute the normal // If we have a triangle and it is static, recompute the normal
if(tri && btRigidBody::upcast(b)->getInvMass()==0) if(tri && co->isStaticOrKinematicObject())
{ {
normalInB = (tri->m_vertices1[1]-tri->m_vertices1[0]) normalInB = (tri->m_vertices1[1]-tri->m_vertices1[0])
.cross(tri->m_vertices1[2]-tri->m_vertices1[0]); .cross(tri->m_vertices1[2]-tri->m_vertices1[0]);