collision detection

Started by
1 comment, last by Richard James 14 years, 6 months ago
well I am still working on a breakout game using opengl and c++.I need to know how to detect how a ball bounces off one of the top bricks.let me know if you need more information or some code.
Advertisement
Here's the code I use

    inline double SqrDist(double x1, double y1, double x2, double y2)    {        return (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);        //Can call SqrDist(x,0,0,0) to square a number    }    inline bool RectCircle(double left, double top, double right, double bot, double circx, double circy, double radius)    {        assert(right>=left);        assert(bot>=top);        assert(radius>=0);        //Check if circle is too far away        if (circx<=left-radius) {return false;}        if (circx>=right+radius) {return false;}        if (circy<=top-radius) {return false;}        if (circy>=bot+radius) {return false;}        //Unless the circle is near the corners, it's a hit        if (circx<=left && circy<=top)        {            if (SqrDist(circx,circy,left,top) > (radius * radius)) {return false;}        }        if (circx<=left && circy>=bot)        {            if (SqrDist(circx,circy,left,bot) > (radius * radius)) {return false;}        }        if (circx>=right && circy<=top)        {            if (SqrDist(circx,circy,right,top) > (radius * radius)) {return false;}        }        if (circx>=right && circy>=bot)        {            if (SqrDist(circx,circy,right,bot) > (radius * radius)) {return false;}        }        return true;    }
I trust exceptions about as far as I can throw them.
Quote:Original post by phil67rpgI need to know how to detect how a ball bounces off one of the top bricks.


What do you mean exactly by that?

Do you want to know how to detect the collision?
Do you want to know how to reflect the ball back towards the bottom?

Do you have the code that works for bouncing the ball off of the walls?

This topic is closed to new replies.

Advertisement