• Create Account

# hentailoli

Member Since 06 Apr 2011
Offline Last Active May 28 2013 09:36 AM

### In Topic: bounding sphere collision detection problem

29 August 2012 - 05:53 AM

Here is an article about sphere-sphere intersection test. Check it out if you want to understand why the following code will work even for fast moving spheres:
http://www.gamedev.n...detection-r1234

```BOOL bSphereTest(CObject3D* obj1, CObject3D* obj2)
{
//Initialize the return value
*t = 0.0f;
// Relative velocity
D3DVECTOR	 dv	  = obj2->prVelocity - obj1->prVelocity;
// Relative position
D3DVECTOR	 dp	  = obj2->prPosition - obj1->prPosition;
//Minimal distance squared
//dP^2-r^2
float pp = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z - r*r;
//(1)Check if the spheres are already intersecting
if ( pp < 0 ) return true;
//dP*dV
float pv	  = dp.x * dv.x + dp.y * dv.y + dp.z * dv.z;
//(2)Check if the spheres are moving away from each other
if ( pv >= 0 ) return false;
//dV^2
float vv = dv.x * dv.x + dv.y * dv.y + dv.z * dv.z;
//(3)Check if the spheres can intersect within 1 frame
if ( (pv + vv) <= 0 && (vv + 2 * pv + pp) >= 0 ) return false;
//tmin = -dP*dV/dV*2
//the time when the distance between the spheres is minimal
float tmin = -pv/vv;
//Discriminant/(4*dV^2) = -(dp^2-r^2+dP*dV*tmin)
return ( pp + pv * tmin > 0 );
}
```

### In Topic: bounding sphere collision detection problem

22 August 2012 - 09:03 AM

The simplest possible way to do bounding-sphere test is to measure the (squared) distance between the two objects in question and to compare the result with the (squared again) sum of their radii. The reason we use the squared distances is to avoid the costly square-root calculation. The code will look something like this:
```bool collide::collision(float x1, float z1, float radius1, float x2, float z2, float radius2)
{
float vecx = x1 - x2;
float vecy = y1 - y2;
float vecz = z1 - z2
float dist = vecx * vecx + vecy * vecy + vecz * vecz;
return dist <= minDist * minDist;
}
```
Keep in mind that if your spheres are moving too fast they will pass through each other.

### In Topic: Template class problems

19 August 2012 - 10:54 AM

Oh thanks that I always wondered why people use .inl and .inc files, but never actually researched it. Well you can close the topic now.

### In Topic: Template class problems

19 August 2012 - 10:35 AM

Thanks for the fast response. Isn't this breaking the good programming practice of separating the definition and implementation? I will move my code, but its definitely something I wish could be done different

### In Topic: vbo and delete

16 August 2012 - 02:03 PM

Even if so, they shouldn't be doing it at runtime.

Sure, there's no need recreating a vbo over and over. But where's the problem deleting the array once the vbo is set up?

I agree. Why would you keep two versions of the same data(one in system memory, other in video memory)? It's the same for textures. You will be needing the data if you plan to animate though.

PARTNERS