27#define USE_PERSISTENT_CONTACTS 1
86#define b2Dot(a, b) (a).dot(b)
87#define b2Mul(a, b) (a) * (b)
88#define b2MulT(a, b) (a).transpose() * (b)
89#define b2Cross(a, b) (a).cross(b)
90#define btCrossS(a, s) btVector3(s* a.getY(), -s* a.getX(), 0.f)
95 const btVector3& normal,
btScalar offset)
105 if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
106 if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
109 if (distance0 * distance1 < 0.0f)
113 vOut[numOut].
v = vIn[0].
v +
interp * (vIn[1].
v - vIn[0].
v);
114 if (distance0 > 0.0f)
116 vOut[numOut].
id = vIn[0].
id;
120 vOut[numOut].
id = vIn[1].
id;
132 const btVector3* vertices1 = poly1->getVertices();
133 const btVector3* normals1 = poly1->getNormals();
135 int count2 = poly2->getVertexCount();
136 const btVector3* vertices2 = poly2->getVertices();
141 btVector3 normal1World =
b2Mul(xf1.getBasis(), normals1[edge1]);
142 btVector3 normal1 =
b2MulT(xf2.getBasis(), normal1World);
149 index = (
int)normal1.minDot(vertices2, count2,
minDot);
151 btVector3 v1 =
b2Mul(xf1, vertices1[edge1]);
152 btVector3
v2 =
b2Mul(xf2, vertices2[index]);
162 int count1 = poly1->getVertexCount();
163 const btVector3* normals1 = poly1->getNormals();
166 btVector3 d =
b2Mul(xf2, poly2->getCentroid()) -
b2Mul(xf1, poly1->getCentroid());
167 btVector3 dLocal1 =
b2MulT(xf1.getBasis(), d);
173 edge = (
int)dLocal1.maxDot(normals1, count1,
maxDot);
183 int prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
191 int nextEdge = edge + 1 < count1 ? edge + 1 : 0;
202 if (sPrev > s && sPrev > sNext)
206 bestSeparation = sPrev;
212 bestSeparation = sNext;
224 edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
226 edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;
234 if (s > bestSeparation)
245 *edgeIndex = bestEdge;
246 return bestSeparation;
253 const btVector3* normals1 = poly1->getNormals();
255 int count2 = poly2->getVertexCount();
256 const btVector3* vertices2 = poly2->getVertices();
257 const btVector3* normals2 = poly2->getNormals();
262 btVector3 normal1 =
b2MulT(xf2.getBasis(),
b2Mul(xf1.getBasis(), normals1[edge1]));
267 for (
int i = 0; i < count2; ++i)
279 int i2 = i1 + 1 < count2 ? i1 + 1 : 0;
281 c[0].
v =
b2Mul(xf2, vertices2[i1]);
286 c[1].
v =
b2Mul(xf2, vertices2[i2]);
305 if (separationA > 0.0f)
310 if (separationB > 0.0f)
318 const btScalar k_relativeTol = 0.98f;
319 const btScalar k_absoluteTol = 0.001f;
322 if (separationB > k_relativeTol * separationA + k_absoluteTol)
344 int count1 = poly1->getVertexCount();
345 const btVector3* vertices1 = poly1->getVertices();
347 btVector3 v11 = vertices1[edge1];
348 btVector3 v12 = edge1 + 1 < count1 ? vertices1[edge1 + 1] : vertices1[0];
351 btVector3 sideNormal =
b2Mul(xf1.getBasis(), v12 - v11);
352 sideNormal.normalize();
353 btVector3 frontNormal =
btCrossS(sideNormal, 1.0f);
355 v11 =
b2Mul(xf1, v11);
356 v12 =
b2Mul(xf1, v12);
364 clipPoints1[0].
v.setValue(0, 0, 0);
365 clipPoints1[1].
v.setValue(0, 0, 0);
368 clipPoints2[0].
v.setValue(0, 0, 0);
369 clipPoints2[1].
v.setValue(0, 0, 0);
388 btVector3 manifoldNormal = flip ? -frontNormal : frontNormal;
393 btScalar separation =
b2Dot(frontNormal, clipPoints2[i].
v) - frontOffset;
395 if (separation <= 0.0f)
402 manifold->addContactPoint(-manifoldNormal, clipPoints2[i].
v, separation);
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2], const btVector3 &normal, btScalar offset)
static btScalar EdgeSeparation(const btBox2dShape *poly1, const btTransform &xf1, int edge1, const btBox2dShape *poly2, const btTransform &xf2)
static void FindIncidentEdge(ClipVertex c[2], const btBox2dShape *poly1, const btTransform &xf1, int edge1, const btBox2dShape *poly2, const btTransform &xf2)
static btScalar FindMaxSeparation(int *edgeIndex, const btBox2dShape *poly1, const btTransform &xf1, const btBox2dShape *poly2, const btTransform &xf2)
void b2CollidePolygons(btManifoldResult *manifold, const btBox2dShape *polyA, const btTransform &xfA, const btBox2dShape *polyB, const btTransform &xfB)
btBox2dShape(const btVector3 &boxHalfExtents)
a btBox2dShape is a flat 2D box in the X-Y plane (Z extents are zero)
int getVertexCount() const
btPersistentManifold * m_manifoldPtr
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
SIMD_FORCE_INLINE long minDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of minimum dot product between this and vectors in array[]
SIMD_FORCE_INLINE long maxDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of maximum dot product between this and vectors in array[]
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
virtual ~btBox2dBox2dCollisionAlgorithm()
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci)
btDispatcher * m_dispatcher
virtual void releaseManifold(btPersistentManifold *manifold)=0
virtual bool needsCollision(const btCollisionObject *body0, const btCollisionObject *body1)=0
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
btManifoldResult is a helper class to manage contact results.
void setPersistentManifold(btPersistentManifold *manifoldPtr)
SIMD_FORCE_INLINE void refreshContactPoints()
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 interp(const float2 a, const float2 b, float t)
SIMD_FORCE_INLINE const btCollisionShape * getCollisionShape() const
SIMD_FORCE_INLINE const btTransform & getWorldTransform() const
SIMD_FORCE_INLINE const btCollisionObject * getCollisionObject() const