70static btVector3
convexHullSupport(
const btVector3& localDirOrg,
const btVector3* points,
int numPoints,
const btVector3& localScaling)
72 btVector3 vec = localDirOrg * localScaling;
74#if defined(__CELLOS_LV2__) && defined(__SPU__)
76 btVector3 localDir = vec;
78 vec_float4 v_distMax = {-
FLT_MAX, 0, 0, 0};
79 vec_int4 v_idxMax = {-999, 0, 0, 0};
81 int numverts = numPoints;
83 for (;
v < (
int)numverts - 4;
v += 4)
85 vec_float4 p0 = vec_dot3(points[
v].get128(), localDir.get128());
86 vec_float4 p1 = vec_dot3(points[
v + 1].get128(), localDir.get128());
87 vec_float4 p2 = vec_dot3(points[
v + 2].get128(), localDir.get128());
88 vec_float4 p3 = vec_dot3(points[
v + 3].get128(), localDir.get128());
89 const vec_int4 i0 = {
v, 0, 0, 0};
90 const vec_int4 i1 = {
v + 1, 0, 0, 0};
91 const vec_int4 i2 = {
v + 2, 0, 0, 0};
92 const vec_int4 i3 = {
v + 3, 0, 0, 0};
93 vec_uint4 retGt01 = spu_cmpgt(p0, p1);
94 vec_float4 pmax01 = spu_sel(p1, p0, retGt01);
95 vec_int4 imax01 = spu_sel(i1, i0, retGt01);
96 vec_uint4 retGt23 = spu_cmpgt(p2, p3);
97 vec_float4 pmax23 = spu_sel(p3, p2, retGt23);
98 vec_int4 imax23 = spu_sel(i3, i2, retGt23);
99 vec_uint4 retGt0123 = spu_cmpgt(pmax01, pmax23);
100 vec_float4 pmax0123 = spu_sel(pmax23, pmax01, retGt0123);
101 vec_int4 imax0123 = spu_sel(imax23, imax01, retGt0123);
102 vec_uint4 retGtMax = spu_cmpgt(v_distMax, pmax0123);
103 v_distMax = spu_sel(pmax0123, v_distMax, retGtMax);
104 v_idxMax = spu_sel(imax0123, v_idxMax, retGtMax);
106 for (;
v < (
int)numverts;
v++)
108 vec_float4 p = vec_dot3(points[
v].get128(), localDir.get128());
109 const vec_int4 i = {
v, 0, 0, 0};
110 vec_uint4 retGtMax = spu_cmpgt(v_distMax, p);
111 v_distMax = spu_sel(p, v_distMax, retGtMax);
112 v_idxMax = spu_sel(i, v_idxMax, retGtMax);
114 int ptIndex = spu_extract(v_idxMax, 0);
115 const btVector3& supVec = points[ptIndex] * localScaling;
120 long ptIndex = vec.maxDot(points, numPoints,
maxDot);
126 btVector3 supVec = points[ptIndex] * localScaling;
131btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual(
const btVector3& localDir)
const
142 const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
144#if defined(__APPLE__) && (defined(BT_USE_SSE) || defined(BT_USE_NEON))
145#if defined(BT_USE_SSE)
146 return btVector3(_mm_xor_ps(_mm_and_ps(localDir.mVec128, (__m128){-0.0f, -0.0f, -0.0f, -0.0f}), halfExtents.mVec128));
147#elif defined(BT_USE_NEON)
148 return btVector3((float32x4_t)(((uint32x4_t)localDir.mVec128 & (uint32x4_t){0x80000000, 0x80000000, 0x80000000, 0x80000000}) ^ (uint32x4_t)halfExtents.mVec128));
150#error unknown vector arch
154 btFsels(localDir.y(), halfExtents.y(), -halfExtents.y()),
155 btFsels(localDir.z(), halfExtents.z(), -halfExtents.z()));
160 btTriangleShape* triangleShape = (btTriangleShape*)
this;
161 btVector3 dir(localDir.getX(), localDir.getY(), localDir.getZ());
162 btVector3* vertices = &triangleShape->m_vertices1[0];
163 btVector3 dots = dir.dot3(vertices[0], vertices[1], vertices[2]);
164 btVector3 sup = vertices[dots.maxAxis()];
165 return btVector3(sup.getX(), sup.getY(), sup.getZ());
169 btCylinderShape* cylShape = (btCylinderShape*)
this;
172 btVector3 halfExtents = cylShape->getImplicitShapeDimensions();
173 btVector3
v(localDir.getX(), localDir.getY(), localDir.getZ());
174 int cylinderUpAxis = cylShape->getUpAxis();
175 int XX(1), YY(0), ZZ(2);
177 switch (cylinderUpAxis)
206 btScalar halfHeight = halfExtents[cylinderUpAxis];
216 tmp[YY] =
v[YY] < 0.0 ? -halfHeight : halfHeight;
218 return btVector3(tmp.getX(), tmp.getY(), tmp.getZ());
223 tmp[YY] =
v[YY] < 0.0 ? -halfHeight : halfHeight;
225 return btVector3(tmp.getX(), tmp.getY(), tmp.getZ());
230 btVector3 vec0(localDir.getX(), localDir.getY(), localDir.getZ());
232 btCapsuleShape* capsuleShape = (btCapsuleShape*)
this;
233 btScalar halfHeight = capsuleShape->getHalfHeight();
234 int capsuleUpAxis = capsuleShape->getUpAxis();
236 btVector3 supVec(0, 0, 0);
240 btVector3 vec = vec0;
244 vec.setValue(1, 0, 0);
254 btVector3
pos(0, 0, 0);
255 pos[capsuleUpAxis] = halfHeight;
258 newDot = vec.dot(vtx);
267 btVector3
pos(0, 0, 0);
268 pos[capsuleUpAxis] = -halfHeight;
271 newDot = vec.dot(vtx);
278 return btVector3(supVec.getX(), supVec.getY(), supVec.getZ());
283 btVector3* points = convexPointCloudShape->getUnscaledPoints();
284 int numPoints = convexPointCloudShape->getNumPoints();
285 return convexHullSupport(localDir, points, numPoints, convexPointCloudShape->getLocalScalingNV());
290 btVector3* points = convexHullShape->getUnscaledPoints();
291 int numPoints = convexHullShape->getNumPoints();
292 return convexHullSupport(localDir, points, numPoints, convexHullShape->getLocalScalingNV());
327 return sphereShape->getRadius();
332 return convexShape->getMarginNV();
336 btTriangleShape* triangleShape = (btTriangleShape*)
this;
337 return triangleShape->getMarginNV();
341 btCylinderShape* cylShape = (btCylinderShape*)
this;
342 return cylShape->getMarginNV();
346 btConeShape* conShape = (btConeShape*)
this;
347 return conShape->getMarginNV();
351 btCapsuleShape* capsuleShape = (btCapsuleShape*)
this;
352 return capsuleShape->getMarginNV();
358 btPolyhedralConvexShape* convexHullShape = (btPolyhedralConvexShape*)
this;
359 return convexHullShape->getMarginNV();
374void btConvexShape::getAabbNonVirtual(
const btTransform& t, btVector3& aabbMin, btVector3& aabbMax)
const
381 btScalar radius = sphereShape->getImplicitShapeDimensions().getX();
382 btScalar margin = radius + sphereShape->getMarginNonVirtual();
383 const btVector3& center = t.getOrigin();
384 btVector3 extent(margin, margin, margin);
385 aabbMin = center - extent;
386 aabbMax = center + extent;
394 btScalar margin = convexShape->getMarginNonVirtual();
395 btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
396 halfExtents +=
btVector3(margin, margin, margin);
398 btVector3 center = t.getOrigin();
399 btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
401 aabbMin = center - extent;
402 aabbMax = center + extent;
407 btTriangleShape* triangleShape = (btTriangleShape*)
this;
408 btScalar margin = triangleShape->getMarginNonVirtual();
409 for (
int i = 0; i < 3; i++)
416 btVector3 tmp = t(sv);
417 aabbMax[i] = tmp[i] + margin;
420 aabbMin[i] = tmp[i] - margin;
426 btCapsuleShape* capsuleShape = (btCapsuleShape*)
this;
427 btVector3 halfExtents(capsuleShape->getRadius(), capsuleShape->getRadius(), capsuleShape->getRadius());
428 int m_upAxis = capsuleShape->getUpAxis();
429 halfExtents[
m_upAxis] = capsuleShape->getRadius() + capsuleShape->getHalfHeight();
431 btVector3 center = t.getOrigin();
432 btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
433 aabbMin = center - extent;
434 aabbMax = center + extent;
441 btScalar margin = convexHullShape->getMarginNonVirtual();
447 this->
getAabb(t, aabbMin, aabbMax);