Repository: bulletphysics/bullet3

Issue:
Points generated by angular perturbation are wrong when object A is rotated
The following gist demonstrates that the location of contact points depends on the order of calls to `btCollisionWorld::addCollisionObject`.

https://gist.github.com/radarsat1/2eb69623b46ee10dfdb52ac617bcc658

It can be run with,

    ./collision_points_object_order | python - &

The program just sets up a collision world with a smaller box as a btConvexHullShape sitting on top of a larger box as a btBoxShape.
With current master (e87060dcf4b445c5c041933b60b9deff9ef98568) it produces the following output:

![image](https://user-images.githubusercontent.com/66805/36311249-73a25246-1309-11e8-8805-8d2de7f52004.png)

Here, points on object A (i.e. getBody0) are blue, points on object B (getBody1) are red.  It seems that btConvexConvexAlgorithm correctly always selects to perturb the smaller object (the convex hull) but when it is A it generates the wrong points.  That is, they are not on the surface of either object.  I think the same points should be generated in both cases.  I think it is a wrong direction of the normal, or a wrong calculation.  I found a possible solution but am still verifying it.  I will submit a PR soon.


Discussion:

Patch:
diff --git a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
index b54bd48932..960861b52d 100644
--- a/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
+++ b/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
@@ -259,7 +259,7 @@ struct btPerturbedContactResult : public btManifoldResult
 			btVector3 endPtOrg = pointInWorld + normalOnBInWorld*orgDepth;
 			endPt = (m_unPerturbedTransform*m_transformA.inverse())(endPtOrg);
 			newDepth = (endPt -  pointInWorld).dot(normalOnBInWorld);
-			startPt = endPt+normalOnBInWorld*newDepth;
+			startPt = endPt - normalOnBInWorld*newDepth;
 		} else
 		{
 			endPt = pointInWorld + normalOnBInWorld*orgDepth;