Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Making SAT for rotation shape  (Read 1697 times)

0 Members and 1 Guest are viewing this topic.

amited

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Making SAT for rotation shape
« on: September 10, 2018, 11:13:34 pm »
Yo. Im writting a game in which player is shotting with computer bots. I have done movement player and collisions with "right" set wall rotation(0,90,180,270,360). But if change rotation of wall then algorithm for SAT doesnt work good like this on ss:
Work good:

And dont work good:


So if you saw, if i changed rotation then sat doesnt works good ;/ This algorithm isnt main. I get this form this film:
and code looks like this:
bool Player::Sat(const Sprite &sp1, const Sprite &sp2, Vector2f *out_mtv)
{               const FloatRect &rectSp1 = sp1.getGlobalBounds();
                const FloatRect &rectSp2 = sp2.getGlobalBounds();
                float proj_x, proj_y, overlap_x, overlap_y;

                // test overlap in x axis
                proj_x = max(rectSp1.left + rectSp1.width, rectSp2.left + rectSp2.width) - min(rectSp1.left, rectSp2.left);
                if (proj_x < rectSp1.width + rectSp2.width) {
                        if (out_mtv) {
                                // calculate mtv in x
                                overlap_x = rectSp1.width + rectSp2.width - proj_x;
                        }
                        // test overlap in y axis
                        proj_y = max(rectSp1.top + rectSp1.height, rectSp2.top + rectSp2.height) - min(rectSp1.top, rectSp2.top);
                        if (proj_y < rectSp1.height + rectSp2.height)
                        {
                                if (out_mtv)
                                {
                                        // calculate mtv in y
                                        overlap_y = rectSp1.height + rectSp2.height - proj_y;
                                        out_mtv->x = out_mtv->y = 0;

                                        // choose minimun overlap
                                        if (overlap_x < overlap_y) {
                                                out_mtv->x = overlap_x * (rectSp1.left < rectSp2.left ? -1 : 1);
                                        }
                                        else {
                                                out_mtv->y = overlap_y * (rectSp1.top < rectSp2.top ? -1 : 1);
                                        }
                                }
                                return true;
                        }
                }
                return false;
}
 
Im writing in sfml like 5 days and sat algorithm is too difficult ;/ Can you give me hint how i have change this code to get the perfect sat algorithm? I know i have to use .getTransform but its a bit difficult for me ;d

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Making SAT for rotation shape
« Reply #1 on: September 12, 2018, 08:01:11 pm »
Maybe you'll find use of this:
https://github.com/SFML/SFML/wiki/Source%3A-Rectangular-Boundary-Collision

If you don't want to use it directly, you could adapt the code for what you need but the SAT is all there. Note, though, that this SAT implementation is customised to only work with rectangular shapes.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

amited

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Making SAT for rotation shape
« Reply #2 on: September 12, 2018, 10:05:40 pm »
Why i dont saw your code ;// Thanks you!