velocityNew = pn * (pn.dot(velocityOld));
startPoint = collisionPoint;
endPoint = startPoint + velocityNew,
until a number of iterations have passed or velocityNew has a small enough magnitude.
The code is very short and can explain better what am i doing:
Code: Select all
bool collision = false;
int i;
for (i=0; i<10; i++)
{
if (vel.length() < 0.00001f)
break;
float radius = 150.0f;
e = s+vel;
btCollisionWorld::ClosestConvexResultCallback cb(s, e);
btSphereShape sphere(radius);
btTransform from(btMatrix3x3().getIdentity(), s);
btTransform to(btMatrix3x3().getIdentity(), e);
collisionWorld->convexSweepTest(&sphere, from, to, cb);
if (cb.hasHit())
{
point = cb.m_hitPointWorld;
normal = cb.m_hitNormalWorld;
btVector3 n = normal;
n.normalize();
btVector3 newPos = point + n * radius;
s = newPos;
btVector3 dir = e - s;
btVector3 parallel = btDot(n, dir)*n;
btVector3 perpendicular = dir - parallel;
perpendicular.normalize();
vel = perpendicular*((vel).dot(perpendicular));
collision = true;
}else
break;
}
if (!collision)
s = e;