   Sphere-Sphere Sweep Test
  Hi I'm using the code exactly as found here:http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php?page=2and it simply fails, I've compared to other sweep sphere code and it seems to be the same code/formula. [depressed] Does anyone have an idea or got some working code?This is a test with values demonstrating it doesn't work.#include "stdio.h"#include "stdlib.h"#include "conio.h"#include <math.h>//simple vector classstruct VECTOR{VECTOR(float ix, float iy, float iz){x=ix;y=iy;z=iz;}float x,y,z;float dot(const VECTOR &v) const{return (x*v.x) + (y*v.y) + (z * v.z);};VECTORoperator - ( const VECTOR& v ) const{    return VECTOR(x - v.x, y - v.y, z - v.z);}};typedef double SCALAR;//code from gamasutratemplate< class T >//swap the values of a and binline void SWAP( T& a, T& b ){const T temp = a;a = b;b = temp; }// Return true if r1 and r2 are realinline bool QuadraticFormula ( const SCALAR a, const SCALAR b, const SCALAR c, SCALAR& r1, SCALAR& r2 ){const SCALAR q = b*b - 4*a*c;if( q >= 0 ) //<------------------------------------ q is -29600000{const SCALAR sq = sqrt(q);const SCALAR d = 1 / (2*a);r1 = ( -b + sq ) * d;r2 = ( -b - sq ) * d;return true;//real roots}return false;//complex roots}const bool SphereSphereSweep( const SCALAR ra, //radius of sphere A const VECTOR& A0, //previous position of sphere A const VECTOR& A1, //current position of sphere A const SCALAR rb, //radius of sphere B const VECTOR& B0, //previous position of sphere B const VECTOR& B1, //current position of sphere B SCALAR& u0, //normalized time of first collision SCALAR& u1 //normalized time of second collision ){const VECTOR va = A1 - A0;//vector from A0 to A1const VECTOR vb = B1 - B0;//vector from B0 to B1const VECTOR AB = B0 - A0;//vector from A0 to B0const VECTOR vab = vb - va;//relative velocity (in normalized time)const SCALAR rab = ra + rb;const SCALAR a = vab.dot(vab);//u*u coefficientconst SCALAR b = 2*vab.dot(AB);//u coefficientconst SCALAR c = AB.dot(AB) - rab*rab;//constant term //check if they're currently overlappingif( AB.dot(AB) <= rab*rab ){u0 = 0;u1 = 0;return true;}//check if they hit each other during the frameif( QuadraticFormula( a, b, c, u0, u1 ) ){if( u0 > u1 )SWAP( u0, u1 );return true;}return false;} //my test int main(int numargs, char*myargs){//first sweep sphereVECTOR old1(100.f, 0.f, 0.f);VECTOR new1(-100.f, 0.f, 0.f);//second sweep sphereVECTOR old2(45.f, 60.f, 0.f);VECTOR new2(45.f, -60.f, 0.f);SCALAR m1;SCALAR m2;if( SphereSphereSweep(10.f,old1, new1, 10.f, old2, new2, m1, m2 ) ){int asd =0;//always comes in here}return 0;}any help? thanks[Edited by - chris2001net on April 29, 2010 4:46:22 PM]
Quote:VECTOR old1(100.f, 0.f, 0.f);VECTOR new1(-100.f, 0.f, 0.f);VECTOR old2(45.f, 60.f, 0.f);VECTOR new2(45.f, -60.f, 0.f);Are you positive that this configuration should result in an intersection?Maybe just as a test you could try a configuration for which it can be said with certainty that an intersection will occur, such as the first sphere going from (-100, 0) to (100, 0) and the second sphere going from (0, -100) to (0, 100).   ;  gah just figured out its time based what I need something different a swept sphere to line segment test.[Edited by - chris2001net on April 30, 2010 6:56:20 AM]