Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2011-03-12 23:34:17 +0300
committerErwin Coumans <blender@erwincoumans.com>2011-03-12 23:34:17 +0300
commit5e374328a87c1b418f8454d5ef38470484804961 (patch)
tree1d6de85165175c5192f74dbd423e1d5cb48f8ff6 /extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
parent8c526e79e31d40d56a6fecce9343c74bd9fe62d8 (diff)
update Bullet physics sdk to latest trunk/version 2.78
add PhysicsConstraints.exportBulletFile(char* fileName) python command I'll be checking the bf-committers mailing list, in case this commit broke stuff scons needs to be updated, I'll do that in a second.
Diffstat (limited to 'extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp')
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp64
1 files changed, 28 insertions, 36 deletions
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
index 9a749a03793..23a5c7526b4 100644
--- a/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
@@ -37,7 +37,7 @@ void SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input,Res
btVector3 point,normal;
btScalar timeOfImpact = btScalar(1.);
btScalar depth = btScalar(0.);
-// output.m_distance = btScalar(1e30);
+// output.m_distance = btScalar(BT_LARGE_FLOAT);
//move sphere into triangle space
btTransform sphereInTr = transformB.inverseTimes(transformA);
@@ -57,8 +57,6 @@ void SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input,Res
}
-#define MAX_OVERLAP btScalar(0.)
-
// See also geometrictools.com
@@ -93,48 +91,39 @@ bool SphereTriangleDetector::facecontains(const btVector3 &p,const btVector3* ve
return pointInTriangle(vertices, lnormal, &lp);
}
-///combined discrete/continuous sphere-triangle
bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold)
{
const btVector3* vertices = &m_triangle->getVertexPtr(0);
- const btVector3& c = sphereCenter;
- btScalar r = m_sphere->getRadius();
-
- btVector3 delta (0,0,0);
+
+ btScalar radius = m_sphere->getRadius();
+ btScalar radiusWithThreshold = radius + contactBreakingThreshold;
btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
normal.normalize();
- btVector3 p1ToCentre = c - vertices[0];
+ btVector3 p1ToCentre = sphereCenter - vertices[0];
btScalar distanceFromPlane = p1ToCentre.dot(normal);
if (distanceFromPlane < btScalar(0.))
{
//triangle facing the other way
-
distanceFromPlane *= btScalar(-1.);
normal *= btScalar(-1.);
}
- btScalar contactMargin = contactBreakingThreshold;
- bool isInsideContactPlane = distanceFromPlane < r + contactMargin;
- bool isInsideShellPlane = distanceFromPlane < r;
+ bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
- btScalar deltaDotNormal = delta.dot(normal);
- if (!isInsideShellPlane && deltaDotNormal >= btScalar(0.0))
- return false;
-
// Check for contact / intersection
bool hasContact = false;
btVector3 contactPoint;
if (isInsideContactPlane) {
- if (facecontains(c,vertices,normal)) {
+ if (facecontains(sphereCenter,vertices,normal)) {
// Inside the contact wedge - touches a point on the shell plane
hasContact = true;
- contactPoint = c - normal*distanceFromPlane;
+ contactPoint = sphereCenter - normal*distanceFromPlane;
} else {
// Could be inside one of the contact capsules
- btScalar contactCapsuleRadiusSqr = (r + contactMargin) * (r + contactMargin);
+ btScalar contactCapsuleRadiusSqr = radiusWithThreshold*radiusWithThreshold;
btVector3 nearestOnEdge;
for (int i = 0; i < m_triangle->getNumEdges(); i++) {
@@ -143,7 +132,7 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
m_triangle->getEdge(i,pa,pb);
- btScalar distanceSqr = SegmentSqrDistance(pa,pb,c, nearestOnEdge);
+ btScalar distanceSqr = SegmentSqrDistance(pa,pb,sphereCenter, nearestOnEdge);
if (distanceSqr < contactCapsuleRadiusSqr) {
// Yep, we're inside a capsule
hasContact = true;
@@ -155,24 +144,27 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
}
if (hasContact) {
- btVector3 contactToCentre = c - contactPoint;
+ btVector3 contactToCentre = sphereCenter - contactPoint;
btScalar distanceSqr = contactToCentre.length2();
- if (distanceSqr < (r - MAX_OVERLAP)*(r - MAX_OVERLAP)) {
- btScalar distance = btSqrt(distanceSqr);
- resultNormal = contactToCentre;
- resultNormal.normalize();
- point = contactPoint;
- depth = -(r-distance);
+
+ if (distanceSqr < radiusWithThreshold*radiusWithThreshold)
+ {
+ if (distanceSqr>SIMD_EPSILON)
+ {
+ btScalar distance = btSqrt(distanceSqr);
+ resultNormal = contactToCentre;
+ resultNormal.normalize();
+ point = contactPoint;
+ depth = -(radius-distance);
+ } else
+ {
+ btScalar distance = 0.f;
+ resultNormal = normal;
+ point = contactPoint;
+ depth = -radius;
+ }
return true;
}
-
- if (delta.dot(contactToCentre) >= btScalar(0.0))
- return false;
-
- // Moving towards the contact point -> collision
- point = contactPoint;
- timeOfImpact = btScalar(0.0);
- return true;
}
return false;