Jump to content
  • Advertisement
Sign in to follow this  
fguihen

finding point of collision

This topic is 4976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i apologise for all the posts today. im trying to get as much work done as possible today and tomorrow. ok, my charachter has a bounding sphere and my wall has an axis alligned bounding box. i know when a collision occours by just comparing the box max and min against the sphere center + radius. what i cant find is the exact point of collision. i think i need this for when i am creating a new vector to make my charachter change direction. thanks all

Share this post


Link to post
Share on other sites
Advertisement
dude, if this didn't help, ...

replace

if (Bcoll.x < Box.Min.x) Bcoll.x = Box.Min.x; else if (Bcoll.x > Box.Max.x) Bcoll.x = Box.Max.x;
if (Bcoll.y < Box.Min.y) Bcoll.y = Box.Min.y; else if (Bcoll.y > Box.Max.y) Bcoll.y = Box.Max.y;
if (Bcoll.z < Box.Min.z) Bcoll.z = Box.Min.z; else if (Bcoll.z > Box.Max.z) Bcoll.z = Box.Max.z;



with



dx0 = (Box.Min.x - Sphere.Centre.x);
dx1 = (Box.Max.x - Sphere.Centre.x);

dy0 = (Box.Min.y - Sphere.Centre.y);
dy1 = (Box.Max.y - Sphere.Centre.y);

dz0 = (Box.Min.z - Sphere.Centre.z);
dz1 = (Box.Max.z - Sphere.Centre.z);

bool outx = (dx0 > 0.0f) || (dx1 < 0.0f);
bool outy = (dy0 > 0.0f) || (dy1 < 0.0f);
bool outz = (dz0 > 0.0f) || (dz1 < 0.0f);

Vector Bcoll;

if (outx || outy || outz)
{
if (Bcoll.x < Box.Min.x) Bcoll.x = Box.Min.x; else if (Bcoll.x > Box.Max.x) Bcoll.x = Box.Max.x;
if (Bcoll.y < Box.Min.y) Bcoll.y = Box.Min.y; else if (Bcoll.y > Box.Max.y) Bcoll.y = Box.Max.y;
if (Bcoll.z < Box.Min.z) Bcoll.z = Box.Min.z; else if (Bcoll.z > Box.Max.z) Bcoll.z = Box.Max.z;
}
else
{
Bcoll = Sphere.Centre;
Vector Delta((-dx0 < dx1)? dx0 : dx1,
(-dy0 < dy1)? dy0 : dy1,
(-dz0 > dz1)? dz0 : dz1);

float min = fabs(Delta.x);
if (fabs(Delta.y) < min)
{
min = fabs(Delta.y);
Delta.x = 0.0f;
}
else
{
Delta.y = 0.0f;
}
if (fabs(Delta.z) < min)
{
Delta.x = Delta.y = 0.0f;
}
else
{
Delta.z = 0.0f;
}

Bcoll += Delta;
}

Share this post


Link to post
Share on other sites
:)

the code snippet above should handle the case when the sphere centre is inside the box (whereas before, it didn't), and return the point of collision on the box perimeter.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!