Rename btCollisionWorld::convexTest to btCollisionWorld::convexSweepTest. The new test sweeps the convex shape against all objects in the world taking into account the orientation specified in the from and to transformations.
This commit is contained in:
@@ -41,6 +41,7 @@ public:
|
||||
btVector3 direction[NUMRAYS_IN_BAR];
|
||||
btVector3 hit_com[NUMRAYS_IN_BAR];
|
||||
btVector3 hit_surface[NUMRAYS_IN_BAR];
|
||||
btScalar hit_fraction[NUMRAYS_IN_BAR];
|
||||
btVector3 normal[NUMRAYS_IN_BAR];
|
||||
|
||||
int frame_counter;
|
||||
@@ -154,17 +155,24 @@ public:
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
btCollisionWorld::ClosestConvexResultCallback cb(source[i], dest[i]);
|
||||
|
||||
cw->convexTest (&boxShape, source[i], dest[i], cb);
|
||||
btQuaternion qFrom;
|
||||
btQuaternion qTo;
|
||||
qFrom.setRotation (btVector3(1.0, 0.0, 0.0), 0.0);
|
||||
qTo.setRotation (btVector3(1.0, 0.0, 0.0), 0.7);
|
||||
btTransform from(qFrom, source[i]);
|
||||
btTransform to(qTo, dest[i]);
|
||||
cw->convexSweepTest (&boxShape, from, to, cb);
|
||||
if (cb.HasHit ())
|
||||
{
|
||||
hit_surface[i] = cb.m_hitPointWorld;
|
||||
hit_com[i].setInterpolate3(source[i], dest[i], cb.m_closestHitFraction);
|
||||
hit_fraction[i] = cb.m_closestHitFraction;
|
||||
normal[i] = cb.m_hitNormalWorld;
|
||||
normal[i].normalize ();
|
||||
} else {
|
||||
hit_com[i] = dest[i];
|
||||
hit_surface[i] = dest[i];
|
||||
hit_fraction[i] = 1.0f;
|
||||
normal[i] = btVector3(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
@@ -187,10 +195,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void drawCube (const btVector3& com)
|
||||
void drawCube (const btTransform& T)
|
||||
{
|
||||
btScalar m[16];
|
||||
T.getOpenGLMatrix (&m[0]);
|
||||
glPushMatrix ();
|
||||
glTranslatef (com[0], com[1], com[2]);
|
||||
glMultMatrixf (&m[0]);
|
||||
glScalef (2.0 * boxShapeHalfExtents[0], 2.0 * boxShapeHalfExtents[1], 2.0 * boxShapeHalfExtents[2]);
|
||||
glutSolidCube (1.0);
|
||||
glPopMatrix ();
|
||||
@@ -216,9 +226,19 @@ public:
|
||||
}
|
||||
glEnd ();
|
||||
glColor3f (0.0, 1.0, 1.0);
|
||||
btQuaternion qFrom;
|
||||
btQuaternion qTo;
|
||||
qFrom.setRotation (btVector3(1.0, 0.0, 0.0), 0.0);
|
||||
qTo.setRotation (btVector3(1.0, 0.0, 0.0), 0.7);
|
||||
for (int i = 0; i < NUMRAYS_IN_BAR; i++)
|
||||
{
|
||||
drawCube (hit_com[i]);
|
||||
btTransform from(qFrom, source[i]);
|
||||
btTransform to(qTo, dest[i]);
|
||||
btVector3 linVel, angVel;
|
||||
btTransformUtil::calculateVelocity (from, to, 1.0, linVel, angVel);
|
||||
btTransform T;
|
||||
btTransformUtil::integrateTransform (from, linVel, angVel, hit_fraction[i], T);
|
||||
drawCube (T);
|
||||
}
|
||||
glEnable (GL_LIGHTING);
|
||||
}
|
||||
|
||||
@@ -620,17 +620,18 @@ void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& r
|
||||
|
||||
}
|
||||
|
||||
void btCollisionWorld::convexTest(const btConvexShape* castShape, const btVector3& convexFromWorld, const btVector3& convexToWorld, ConvexResultCallback& resultCallback,short int collisionFilterMask)
|
||||
void btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, ConvexResultCallback& resultCallback,short int collisionFilterMask)
|
||||
{
|
||||
btTransform convexFromTrans,convexToTrans;
|
||||
convexFromTrans.setIdentity();
|
||||
convexFromTrans.setOrigin(convexFromWorld);
|
||||
convexToTrans.setIdentity();
|
||||
convexToTrans.setOrigin(convexToWorld);
|
||||
convexFromTrans = convexFromWorld;
|
||||
convexToTrans = convexToWorld;
|
||||
btVector3 castShapeAabbMin, castShapeAabbMax;
|
||||
btTransform I;
|
||||
I.setIdentity();
|
||||
castShape->getAabb (I, castShapeAabbMin, castShapeAabbMax);
|
||||
/* Compute AABB that encompasses movement */
|
||||
{
|
||||
btVector3 linVel, angVel;
|
||||
btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
|
||||
castShape->calculateTemporalAabb (convexFromTrans, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
|
||||
}
|
||||
|
||||
/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
|
||||
// do a ray-shape query using convexCaster (CCD)
|
||||
@@ -646,7 +647,7 @@ void btCollisionWorld::convexTest(const btConvexShape* castShape, const btVector
|
||||
AabbExpand (collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
|
||||
btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
|
||||
btVector3 hitNormal;
|
||||
if (btRayAabb(convexFromWorld,convexToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
|
||||
if (btRayAabb(convexFromWorld.getOrigin(),convexToWorld.getOrigin(),collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
|
||||
{
|
||||
objectQuerySingle(castShape, convexFromTrans,convexToTrans,
|
||||
collisionObject,
|
||||
|
||||
@@ -307,9 +307,10 @@ public:
|
||||
/// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
|
||||
void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback, short int collisionFilterMask=-1);
|
||||
|
||||
// convexTest performs a linear convex cast on all objects in the btCollisionWorld, and calls the resultCallback
|
||||
// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback
|
||||
// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
|
||||
void convexTest (const btConvexShape* castShape, const btVector3& from, const btVector3& to, ConvexResultCallback& resultCallback, short int collisionFilterMask=-1);
|
||||
void convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback, short int collisionFilterMask=-1);
|
||||
|
||||
|
||||
/// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
|
||||
/// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.
|
||||
|
||||
@@ -46,7 +46,7 @@ btScalar btCollisionShape::getAngularMotionDisc() const
|
||||
return disc;
|
||||
}
|
||||
|
||||
void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax)
|
||||
void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
|
||||
{
|
||||
//start with static aabb
|
||||
getAabb(curTrans,temporalAabbMin,temporalAabbMax);
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
|
||||
///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
|
||||
///result is conservative
|
||||
void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax);
|
||||
void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
|
||||
|
||||
#ifndef __SPU__
|
||||
|
||||
|
||||
Reference in New Issue
Block a user