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

Author Topic: How Can i draw a simple Concave Shape?  (Read 6665 times)

0 Members and 2 Guests are viewing this topic.

freekill

  • Newbie
  • *
  • Posts: 9
    • View Profile
How Can i draw a simple Concave Shape?
« on: May 02, 2015, 02:08:05 pm »
Hi!

Firstly, Sorry for my bad english. I have a big problem. I am creating game which look and is like Mamba. My character moves in 4 directions. To create shape, i have X,Y coordinates, and number of points. I need to create shapes which consist only from rectangles. So, some of them will be concave.

        shape.setPointCount(6);
        shape.setPoint(0, sf::Vector2f(60, 60));
        shape.setPoint(1, sf::Vector2f(120, 60));
        shape.setPoint(2, sf::Vector2f(120, 120));
        shape.setPoint(3, sf::Vector2f(200, 120));
        shape.setPoint(4, sf::Vector2f(200, 150));
        shape.setPoint(5, sf::Vector2f(60, 150));
        shape.setPosition(50, 50);
        shape.setOutlineThickness(1);
        shape.setFillColor(Color::Red);
        shape.setOutlineColor(Color::Black);
 

and the result:




SFML not support Concave Shapes, only COnvex, but i read documentation of SFML that TrianglesFan can do it, but not exactly. Not all shapes, can be make from triangles. For Example


or

So, i found, that Thor supports Concave Shapes. Yes, but i have another problem. It not supports GetingGlobalBounds function , which i must use to detect Collision.

Any ideas?  Or algorithm making from these shapes multiple triangles, when we only have coordinates in specific order(0 to 6)?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How Can i draw a simple Concave Shape?
« Reply #1 on: May 02, 2015, 02:15:21 pm »
So, i found, that Thor supports Concave Shapes. Yes, but i have another problem. It not supports GetingGlobalBounds function , which i must use to detect Collision.
I could probably add such a function.

In the meantime, you can compute the bounding rect by iterating through the vertices.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

freekill

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: How Can i draw a simple Concave Shape?
« Reply #2 on: May 02, 2015, 02:44:17 pm »
wow, thank for fast reply!

I don't quite understand what mean to 'compute bounding rect'? This means to compute the top, right, left and bottom of shape? Can you please explain this ? or give me some example of it?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How Can i draw a simple Concave Shape?
« Reply #3 on: May 02, 2015, 03:01:13 pm »
Basically this. Start with a small rectangle and enlarge it for every point.

But I'll implement it very shortly in Thor, so if you have some patience... :)
« Last Edit: May 02, 2015, 03:04:08 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How Can i draw a simple Concave Shape?
« Reply #4 on: May 02, 2015, 05:46:20 pm »
I pushed a revision with thor::ConcaveShape::getGlobalBounds() and used the opportunity to modernize the code altogether.

At the moment, global bounds will be of limited utility for collision because of this problem -- at least when you rotate your shapes.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

freekill

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: How Can i draw a simple Concave Shape?
« Reply #5 on: June 03, 2015, 02:35:26 pm »
I tested it, and when i try to detect when one object intersect my ConcaveShape, it detect it on the Rectangle Area of My shape... i didnt ttry to rotate shapes.

Its something like this:



Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: How Can i draw a simple Concave Shape?
« Reply #6 on: June 03, 2015, 03:35:29 pm »
GetGlobalBounds() give you a Rect that contains your shape.
So it's corret when you get a collision in your second case.

You can use it for a simple collision detection and if you get a collision you would have to check in detail.

freekill

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: How Can i draw a simple Concave Shape?
« Reply #7 on: June 03, 2015, 03:40:41 pm »
Yes i know it, but when i tested that GetGlobalBounds, i have my 1st case. I had written collision function, but what i presenting here is unexpected problem ( 2nd case).

So thats why im posting, becasue in practise i received that shown situation.

Its not quite allright for me as user, to receive Collision from normal Shape like Rectangle, when i use ConcaveShape...

So, in the end its not possible to give me that what i expected (on the image)?
« Last Edit: June 03, 2015, 03:49:17 pm by freekill »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: How Can i draw a simple Concave Shape?
« Reply #8 on: June 03, 2015, 04:55:00 pm »
It is possible to get what you want, but you won't be able to just use a built-in SFML function for that purpose. As Ghosa mentioned, it is expected that only using GetGlobalBounds to calculate collision boxes will cause situation 2 will generate a collision. Once you see a collision you need to add another step that uses a more precise collision method to see if you are really colliding. There are several different ways to do this depending on how complex your game needs to be (if the shapes can rotate, etc), but again there isn't a SFML function that can achieve this on its own. Can you split your shape into individual rectangles and check against collision on each one?

freekill

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: How Can i draw a simple Concave Shape?
« Reply #9 on: June 03, 2015, 05:55:54 pm »
Yes, I can do it, but i dont have much time to make algoritm for this. Its too late, for my project. Im wonder which algorithm can do that ( i read a lot about triangulation) but its too hard for me, because i can create whatever concave and convex shape(Look in images on first post). So, TY for all replies.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How Can i draw a simple Concave Shape?
« Reply #10 on: June 03, 2015, 07:16:54 pm »
As clearly stated in the documentation and in the thread I linked, the bounding rect isn't accurate. This is a trade-off between performance and usefulness. And of course, a bounding rect will not account for sub-rectangles excluded in the shape... After all, it's one rectangle.

Thor provides Delaunay Triangulation in the Math module. Once you have the triangles, collision detection is trivial.

Alternatively, Boost.Geometry with polygons and intersection algorithms.
« Last Edit: June 03, 2015, 07:19:38 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything