Public Group

Precision Problems with bouding sphere

Recommended Posts

I tried to make two spheres with bounding sphere to detect collision so they stop when they collide. But it seems that im having a precision issue. They stey stuck together because of small decimal keeping it stuck. Is there a way around this? Since they are in a 3d space, adding or subtracting a little off seems impossible and expensive. How can I solve these precision issues?

The code I used.

oldleftright = leftright, oldupdown = updown;

if(GetAsyncKeyState(VK_RIGHT))
leftright += 0.0001;
if(GetAsyncKeyState(VK_LEFT))
leftright -= 0.0001;
if(GetAsyncKeyState(VK_DOWN))
updown -= 0.0001;
if(GetAsyncKeyState(VK_UP))
updown += 0.0001;

collide = test.Intersect(test2);
if (collide)
{
leftright = oldleftright;
updown = oldupdown;
}
collide = false;

Share on other sites

I think you need to compute the amount of intersection between the spheres and use that to push either one sphere or both of them away from each other so they stop intersecting.

Share on other sites

Alright, I got to work. thx

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×