finding point of collision

Started by
2 comments, last by oliii 19 years, 3 months ago
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
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
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;}

Everything is better with Metal.

i apologise, i didnt even think to look at my older post. thanks
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
:)

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.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement