Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: merge bullet3 into src (pt. 01) #260

Merged
merged 9 commits into from
Jan 31, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ class btAxisSweep3Internal : public btBroadphaseInterface
{
/* printf("btAxisSweep3.h\n");
printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
printf("aabbMin=%f,%f,%f,aabbMax=%f,%f,%f\n",m_worldAabbMin.getX(),m_worldAabbMin.getY(),m_worldAabbMin.getZ(),
m_worldAabbMax.getX(),m_worldAabbMax.getY(),m_worldAabbMax.getZ());
printf("aabbMin=%f,%f,%f,aabbMax=%f,%f,%f\n",m_worldAabbMin.x,m_worldAabbMin.y,m_worldAabbMin.z,
m_worldAabbMax.x,m_worldAabbMax.y,m_worldAabbMax.z);
*/
}
};
Expand Down Expand Up @@ -320,10 +320,10 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::unQuantize(btBroadphaseProxy* proxy,
vecInMin[2] = m_pEdges[2][pHandle->m_minEdges[2]].m_pos;
vecInMax[2] = m_pEdges[2][pHandle->m_maxEdges[2]].m_pos + 1;

aabbMin.setValue((btScalar)(vecInMin[0]) / (m_quantize.getX()), (btScalar)(vecInMin[1]) / (m_quantize.getY()), (btScalar)(vecInMin[2]) / (m_quantize.getZ()));
aabbMin.setValue((btScalar)(vecInMin[0]) / (m_quantize.x), (btScalar)(vecInMin[1]) / (m_quantize.y), (btScalar)(vecInMin[2]) / (m_quantize.z));
aabbMin += m_worldAabbMin;

aabbMax.setValue((btScalar)(vecInMax[0]) / (m_quantize.getX()), (btScalar)(vecInMax[1]) / (m_quantize.getY()), (btScalar)(vecInMax[2]) / (m_quantize.getZ()));
aabbMax.setValue((btScalar)(vecInMax[0]) / (m_quantize.x), (btScalar)(vecInMax[1]) / (m_quantize.y), (btScalar)(vecInMax[2]) / (m_quantize.z));
aabbMax += m_worldAabbMin;
}

Expand Down Expand Up @@ -442,9 +442,9 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::quantize(BP_FP_INT_TYPE* out, const b
clampedPoint.setMax(m_worldAabbMin);
clampedPoint.setMin(m_worldAabbMax);
btVector3 v = (clampedPoint - m_worldAabbMin) * m_quantize;
out[0] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getX() & m_bpHandleMask) | isMax);
out[1] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getY() & m_bpHandleMask) | isMax);
out[2] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getZ() & m_bpHandleMask) | isMax);
out[0] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.x & m_bpHandleMask) | isMax);
out[1] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.y & m_bpHandleMask) | isMax);
out[2] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.z & m_bpHandleMask) | isMax);
#else
btVector3 v = (point - m_worldAabbMin) * m_quantize;
out[0] = (v[0] <= 0) ? (BP_FP_INT_TYPE)isMax : (v[0] >= m_handleSentinel) ? (BP_FP_INT_TYPE)((m_handleSentinel & m_bpHandleMask) | isMax) : (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v[0] & m_bpHandleMask) | isMax);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static DBVT_INLINE btDbvtVolume merge(const btDbvtVolume& a,
static DBVT_INLINE btScalar size(const btDbvtVolume& a)
{
const btVector3 edges = a.Lengths();
return (edges.x() * edges.y() * edges.z() +
edges.x() + edges.y() + edges.z());
return (edges.x * edges.y * edges.z +
edges.x + edges.y + edges.z);
}

//
Expand Down Expand Up @@ -829,7 +829,7 @@ struct btDbvtBenchmark
static btTransform RandTransform(btScalar cs)
{
btTransform t;
t.setOrigin(RandVector3(cs));
t.m_origin = (RandVector3(cs));
t.setRotation(btQuaternion(RandUnit() * SIMD_PI * 2, RandUnit() * SIMD_PI * 2, RandUnit() * SIMD_PI * 2).normalized());
return (t);
}
Expand Down
118 changes: 59 additions & 59 deletions 3rdparty/bullet3/src/BulletCollision/BroadphaseCollision/btDbvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,29 +520,29 @@ DBVT_INLINE void btDbvtAabbMm::Expand(const btVector3& e)
//
DBVT_INLINE void btDbvtAabbMm::SignedExpand(const btVector3& e)
{
if (e.x() > 0)
mx.setX(mx.x() + e[0]);
if (e.x > 0)
mx.x = (mx.x + e[0]);
else
mi.setX(mi.x() + e[0]);
if (e.y() > 0)
mx.setY(mx.y() + e[1]);
mi.x = (mi.x + e[0]);
if (e.y > 0)
mx.y = (mx.y + e[1]);
else
mi.setY(mi.y() + e[1]);
if (e.z() > 0)
mx.setZ(mx.z() + e[2]);
mi.y = (mi.y + e[1]);
if (e.z > 0)
mx.z = (mx.z + e[2]);
else
mi.setZ(mi.z() + e[2]);
mi.z = (mi.z + e[2]);
}

//
DBVT_INLINE bool btDbvtAabbMm::Contain(const btDbvtAabbMm& a) const
{
return ((mi.x() <= a.mi.x()) &&
(mi.y() <= a.mi.y()) &&
(mi.z() <= a.mi.z()) &&
(mx.x() >= a.mx.x()) &&
(mx.y() >= a.mx.y()) &&
(mx.z() >= a.mx.z()));
return ((mi.x <= a.mi.x) &&
(mi.y <= a.mi.y) &&
(mi.z <= a.mi.z) &&
(mx.x >= a.mx.x) &&
(mx.y >= a.mx.y) &&
(mx.z >= a.mx.z));
}

//
Expand All @@ -552,36 +552,36 @@ DBVT_INLINE int btDbvtAabbMm::Classify(const btVector3& n, btScalar o, int s) co
switch (s)
{
case (0 + 0 + 0):
px = btVector3(mi.x(), mi.y(), mi.z());
pi = btVector3(mx.x(), mx.y(), mx.z());
px = btVector3(mi.x, mi.y, mi.z);
pi = btVector3(mx.x, mx.y, mx.z);
break;
case (1 + 0 + 0):
px = btVector3(mx.x(), mi.y(), mi.z());
pi = btVector3(mi.x(), mx.y(), mx.z());
px = btVector3(mx.x, mi.y, mi.z);
pi = btVector3(mi.x, mx.y, mx.z);
break;
case (0 + 2 + 0):
px = btVector3(mi.x(), mx.y(), mi.z());
pi = btVector3(mx.x(), mi.y(), mx.z());
px = btVector3(mi.x, mx.y, mi.z);
pi = btVector3(mx.x, mi.y, mx.z);
break;
case (1 + 2 + 0):
px = btVector3(mx.x(), mx.y(), mi.z());
pi = btVector3(mi.x(), mi.y(), mx.z());
px = btVector3(mx.x, mx.y, mi.z);
pi = btVector3(mi.x, mi.y, mx.z);
break;
case (0 + 0 + 4):
px = btVector3(mi.x(), mi.y(), mx.z());
pi = btVector3(mx.x(), mx.y(), mi.z());
px = btVector3(mi.x, mi.y, mx.z);
pi = btVector3(mx.x, mx.y, mi.z);
break;
case (1 + 0 + 4):
px = btVector3(mx.x(), mi.y(), mx.z());
pi = btVector3(mi.x(), mx.y(), mi.z());
px = btVector3(mx.x, mi.y, mx.z);
pi = btVector3(mi.x, mx.y, mi.z);
break;
case (0 + 2 + 4):
px = btVector3(mi.x(), mx.y(), mx.z());
pi = btVector3(mx.x(), mi.y(), mi.z());
px = btVector3(mi.x, mx.y, mx.z);
pi = btVector3(mx.x, mi.y, mi.z);
break;
case (1 + 2 + 4):
px = btVector3(mx.x(), mx.y(), mx.z());
pi = btVector3(mi.x(), mi.y(), mi.z());
px = btVector3(mx.x, mx.y, mx.z);
pi = btVector3(mi.x, mi.y, mi.z);
break;
}
if ((btDot(n, px) + o) < 0) return (-1);
Expand All @@ -593,9 +593,9 @@ DBVT_INLINE int btDbvtAabbMm::Classify(const btVector3& n, btScalar o, int s) co
DBVT_INLINE btScalar btDbvtAabbMm::ProjectMinimum(const btVector3& v, unsigned signs) const
{
const btVector3* b[] = {&mx, &mi};
const btVector3 p(b[(signs >> 0) & 1]->x(),
b[(signs >> 1) & 1]->y(),
b[(signs >> 2) & 1]->z());
const btVector3 p(b[(signs >> 0) & 1]->x,
b[(signs >> 1) & 1]->y,
b[(signs >> 2) & 1]->z);
return (btDot(p, v));
}

Expand Down Expand Up @@ -631,25 +631,25 @@ DBVT_INLINE bool Intersect(const btDbvtAabbMm& a,
#endif
return ((pu[0] | pu[1] | pu[2]) == 0);
#else
return ((a.mi.x() <= b.mx.x()) &&
(a.mx.x() >= b.mi.x()) &&
(a.mi.y() <= b.mx.y()) &&
(a.mx.y() >= b.mi.y()) &&
(a.mi.z() <= b.mx.z()) &&
(a.mx.z() >= b.mi.z()));
return ((a.mi.x <= b.mx.x) &&
(a.mx.x >= b.mi.x) &&
(a.mi.y <= b.mx.y) &&
(a.mx.y >= b.mi.y) &&
(a.mi.z <= b.mx.z) &&
(a.mx.z >= b.mi.z));
#endif
}

//
DBVT_INLINE bool Intersect(const btDbvtAabbMm& a,
const btVector3& b)
{
return ((b.x() >= a.mi.x()) &&
(b.y() >= a.mi.y()) &&
(b.z() >= a.mi.z()) &&
(b.x() <= a.mx.x()) &&
(b.y() <= a.mx.y()) &&
(b.z() <= a.mx.z()));
return ((b.x >= a.mi.x) &&
(b.y >= a.mi.y) &&
(b.z >= a.mi.z) &&
(b.x <= a.mx.x) &&
(b.y <= a.mx.y) &&
(b.z <= a.mx.z));
}

//////////////////////////////////////
Expand All @@ -659,7 +659,7 @@ DBVT_INLINE btScalar Proximity(const btDbvtAabbMm& a,
const btDbvtAabbMm& b)
{
const btVector3 d = (a.mi + a.mx) - (b.mi + b.mx);
return (btFabs(d.x()) + btFabs(d.y()) + btFabs(d.z()));
return (btFabs(d.x) + btFabs(d.y) + btFabs(d.z));
}

//
Expand Down Expand Up @@ -774,12 +774,12 @@ DBVT_INLINE void Merge(const btDbvtAabbMm& a,
DBVT_INLINE bool NotEqual(const btDbvtAabbMm& a,
const btDbvtAabbMm& b)
{
return ((a.mi.x() != b.mi.x()) ||
(a.mi.y() != b.mi.y()) ||
(a.mi.z() != b.mi.z()) ||
(a.mx.x() != b.mx.x()) ||
(a.mx.y() != b.mx.y()) ||
(a.mx.z() != b.mx.z()));
return ((a.mi.x != b.mi.x) ||
(a.mi.y != b.mi.y) ||
(a.mi.z != b.mi.z) ||
(a.mx.x != b.mx.x) ||
(a.mx.y != b.mx.y) ||
(a.mx.z != b.mx.z));
}

//
Expand Down Expand Up @@ -1362,9 +1362,9 @@ inline void btDbvt::collideKDOP(const btDbvtNode* root,
btAssert(count < int(sizeof(signs) / sizeof(signs[0])));
for (int i = 0; i < count; ++i)
{
signs[i] = ((normals[i].x() >= 0) ? 1 : 0) +
((normals[i].y() >= 0) ? 2 : 0) +
((normals[i].z() >= 0) ? 4 : 0);
signs[i] = ((normals[i].x >= 0) ? 1 : 0) +
((normals[i].y >= 0) ? 2 : 0) +
((normals[i].z >= 0) ? 4 : 0);
}
stack.reserve(SIMPLE_STACKSIZE);
stack.push_back(sStkNP(root, 0));
Expand Down Expand Up @@ -1429,9 +1429,9 @@ inline void btDbvt::collideOCL(const btDbvtNode* root,
btAssert(count < int(sizeof(signs) / sizeof(signs[0])));
for (int i = 0; i < count; ++i)
{
signs[i] = ((normals[i].x() >= 0) ? 1 : 0) +
((normals[i].y() >= 0) ? 2 : 0) +
((normals[i].z() >= 0) ? 4 : 0);
signs[i] = ((normals[i].x >= 0) ? 1 : 0) +
((normals[i].y >= 0) ? 2 : 0) +
((normals[i].z >= 0) ? 4 : 0);
}
stock.reserve(SIMPLE_STACKSIZE);
stack.reserve(SIMPLE_STACKSIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,61 +329,61 @@ btQuantizedBvh
{
btAssert(m_useQuantization);

btAssert(point.getX() <= m_bvhAabbMax.getX());
btAssert(point.getY() <= m_bvhAabbMax.getY());
btAssert(point.getZ() <= m_bvhAabbMax.getZ());
btAssert(point.x <= m_bvhAabbMax.x);
btAssert(point.y <= m_bvhAabbMax.y);
btAssert(point.z <= m_bvhAabbMax.z);

btAssert(point.getX() >= m_bvhAabbMin.getX());
btAssert(point.getY() >= m_bvhAabbMin.getY());
btAssert(point.getZ() >= m_bvhAabbMin.getZ());
btAssert(point.x >= m_bvhAabbMin.x);
btAssert(point.y >= m_bvhAabbMin.y);
btAssert(point.z >= m_bvhAabbMin.z);

btVector3 v = (point - m_bvhAabbMin) * m_bvhQuantization;
///Make sure rounding is done in a way that unQuantize(quantizeWithClamp(...)) is conservative
///end-points always set the first bit, so that they are sorted properly (so that neighbouring AABBs overlap properly)
///@todo: double-check this
if (isMax)
{
out[0] = (unsigned short)(((unsigned short)(v.getX() + btScalar(1.)) | 1));
out[1] = (unsigned short)(((unsigned short)(v.getY() + btScalar(1.)) | 1));
out[2] = (unsigned short)(((unsigned short)(v.getZ() + btScalar(1.)) | 1));
out[0] = (unsigned short)(((unsigned short)(v.x + btScalar(1.)) | 1));
out[1] = (unsigned short)(((unsigned short)(v.y + btScalar(1.)) | 1));
out[2] = (unsigned short)(((unsigned short)(v.z + btScalar(1.)) | 1));
}
else
{
out[0] = (unsigned short)(((unsigned short)(v.getX()) & 0xfffe));
out[1] = (unsigned short)(((unsigned short)(v.getY()) & 0xfffe));
out[2] = (unsigned short)(((unsigned short)(v.getZ()) & 0xfffe));
out[0] = (unsigned short)(((unsigned short)(v.x) & 0xfffe));
out[1] = (unsigned short)(((unsigned short)(v.y) & 0xfffe));
out[2] = (unsigned short)(((unsigned short)(v.z) & 0xfffe));
}

#ifdef DEBUG_CHECK_DEQUANTIZATION
btVector3 newPoint = unQuantize(out);
if (isMax)
{
if (newPoint.getX() < point.getX())
if (newPoint.x < point.x)
{
printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n", newPoint.getX() - point.getX(), newPoint.getX(), point.getX());
printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n", newPoint.x - point.x, newPoint.x, point.x);
}
if (newPoint.getY() < point.getY())
if (newPoint.y < point.y)
{
printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n", newPoint.getY() - point.getY(), newPoint.getY(), point.getY());
printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n", newPoint.y - point.y, newPoint.y, point.y);
}
if (newPoint.getZ() < point.getZ())
if (newPoint.z < point.z)
{
printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n", newPoint.getZ() - point.getZ(), newPoint.getZ(), point.getZ());
printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n", newPoint.z - point.z, newPoint.z, point.z);
}
}
else
{
if (newPoint.getX() > point.getX())
if (newPoint.x > point.x)
{
printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n", newPoint.getX() - point.getX(), newPoint.getX(), point.getX());
printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n", newPoint.x - point.x, newPoint.x, point.x);
}
if (newPoint.getY() > point.getY())
if (newPoint.y > point.y)
{
printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n", newPoint.getY() - point.getY(), newPoint.getY(), point.getY());
printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n", newPoint.y - point.y, newPoint.y, point.y);
}
if (newPoint.getZ() > point.getZ())
if (newPoint.z > point.z)
{
printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n", newPoint.getZ() - point.getZ(), newPoint.getZ(), point.getZ());
printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n", newPoint.z - point.z, newPoint.z, point.z);
}
}
#endif //DEBUG_CHECK_DEQUANTIZATION
Expand All @@ -404,9 +404,9 @@ btQuantizedBvh
{
btVector3 vecOut;
vecOut.setValue(
(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
(btScalar)(vecIn[0]) / (m_bvhQuantization.x),
(btScalar)(vecIn[1]) / (m_bvhQuantization.y),
(btScalar)(vecIn[2]) / (m_bvhQuantization.z));
vecOut += m_bvhAabbMin;
return vecOut;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org

This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
Expand Down Expand Up @@ -38,18 +38,18 @@ void SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input, Re
//move sphere into triangle space
btTransform sphereInTr = transformB.inverseTimes(transformA);

if (collide(sphereInTr.getOrigin(), point, normal, depth, timeOfImpact, m_contactBreakingThreshold))
if (collide(sphereInTr.m_origin, point, normal, depth, timeOfImpact, m_contactBreakingThreshold))
{
if (swapResults)
{
btVector3 normalOnB = transformB.getBasis() * normal;
btVector3 normalOnB = transformB.m_basis * normal;
btVector3 normalOnA = -normalOnB;
btVector3 pointOnA = transformB * point + normalOnB * depth;
output.addContactPoint(normalOnA, pointOnA, depth);
}
else
{
output.addContactPoint(transformB.getBasis() * normal, transformB * point, depth);
output.addContactPoint(transformB.m_basis * normal, transformB * point, depth);
}
}
}
Expand Down
Loading