SFML community forums

Help => Graphics => Topic started by: Azazel on September 13, 2017, 02:54:21 pm

Title: Inclination of objects from Tiled Map Editor
Post by: Azazel on September 13, 2017, 02:54:21 pm
So, I drew in Tiled Map Editor an isometric map and add layers of object (see the pictures below in a hide).

Then I draw a map through the tinyXml , but with the objects there was a problem. Code I get from https://en.sfml-dev.org/forums/index.php?topic=3023.0 (https://en.sfml-dev.org/forums/index.php?topic=3023.0) but modifies it somewhat for an isometric map. But I could not change the mapping of objects. To get the rect of my layer of objects, i use sf::Rect but i get an ortogonal rectangle
Object object;
object.name = objectName;
object.type = objectType;
object.sprite = sprite;

sf::Rect<float> objectRect;
objectRect.top = y;
objectRect.left = x;
objectRect.height = height;
objectRect.width = width;
object.rect = objectRect;

How can this rectangle of objects be tilted to isometric view?
(click to show/hide)
The white rectangle in the picture is the visualization of my layer of objects, that is, the way it looks in my code.
Full code here https://pastebin.com/U1NG8eKD (https://pastebin.com/U1NG8eKD)
Title: Re: Inclination of objects from Tiled Map Editor
Post by: eXpl0it3r on September 13, 2017, 07:51:35 pm
The sf::Rect can't be tilted. Instead you'll have to write your own tile rect or similar class that uses the correct isometric math.
If you don't know how, you might want to check one of the various websites on isometric math.
Title: Re: Inclination of objects from Tiled Map Editor
Post by: Azazel on September 14, 2017, 06:19:57 pm
So, i create my own "rectangle" with sf::Vertex. How i can check intersection of my Vertex(isometric) rectangle and a standart rectangle with sides parallel to the axes?
(click to show/hide)
Title: Re: Inclination of objects from Tiled Map Editor
Post by: Arcade on September 14, 2017, 07:45:35 pm
It sounds like your basic problem is that you want a way to check collisions between rotated rectangles? SFML doesn't provide a built-in way to do this, but you could implement the "separating axis theorem" for this. You can google that term to find a lot more information on it.