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

Author Topic: [Solved] Transform - Oriented Rectangle  (Read 1460 times)

0 Members and 1 Guest are viewing this topic.

felaugmar

  • Guest
[Solved] Transform - Oriented Rectangle
« on: November 05, 2016, 06:06:01 pm »
Hello,

I know that the 'Transform class' we have in SFML don't have the option to return an oriented rectangle but returns a bounding rectangle which is nice;
But, you guys know any algorithm that returns an array of Points instead?

btw, for now I'm fine with the bounding, I'm just wondering which algorithm can be applied for this.

Thank you.
« Last Edit: November 06, 2016, 01:12:38 am by felaugmar »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Transform - Oriented Rectangle
« Reply #1 on: November 05, 2016, 09:25:18 pm »
An array of points? Do you mean the corners of the rectangle after transformations?
You can use the object's transform to transform the points yourself. The point without the transform can be found from the local bounding rectangle.

You could try something like this (untested):
sf::Transform transform = object.getTransform();
sf::FloatRect localRect = object.getLocalBounds();
std::vector<sf::Vector2f> points(4);
points[0] = transform.transformPoint(sf::Vector2f(localRect.left, localRect.top));
points[1] = transform.transformPoint(sf::Vector2f(localRect.left + localRect.width, localRect.top));
points[2] = transform.transformPoint(sf::Vector2f(localRect.left + localRect.width, localRect.top + localRect.height));
points[3] = transform.transformPoint(sf::Vector2f(localRect.left, localRect.top + localRect.height));
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

felaugmar

  • Guest
Re: Transform - Oriented Rectangle
« Reply #2 on: November 05, 2016, 10:13:23 pm »
What I'm looking after is a vector with all the points inside the area of the rectangle.
something like this \/

sf::Vector2f p1 {10.f, 0}; // top-left point
sf::Vector2f p2 {0, 10.f}; // bottom-left point
sf::Vector2f p3 {10.f, 20.f}; // bottom-right point
sf::Vector2f p4 {20.f, 10.f}; // top-right point

//  The 4 points above would make a rectangle at 45 degrees

std::vector<sf::Vector2i> rectangleAreaPoints = getPointsInsideRectangle(p1, p2, p3, p4);
 

I attached an image, well, I want all the pixels in the black area.
;D
« Last Edit: November 05, 2016, 10:17:20 pm by felaugmar »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
AW: Transform - Oriented Rectangle
« Reply #3 on: November 05, 2016, 10:25:09 pm »
Render to a render texture, copy it to an image and access the image data through the pixel pointer.

Alternativly you can do a point transformation for every point of your rectangle.

Question is, what do you need this for?

If you need an "algorithm" then just look at some transformation math.
« Last Edit: November 05, 2016, 10:27:31 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

felaugmar

  • Guest
Re: Transform - Oriented Rectangle
« Reply #4 on: November 05, 2016, 11:38:47 pm »
I'm maping objects that is appearing in the screen for "mouse collision";
that is, I'm doing a big "2D vector", with the size of the screen,
for example, 1280x720;
Then there's "handlers" in each pixel to some kind of function call (onHover, onStopHover) of some object.

Well, doing point transformation of every point is a way, cool.
« Last Edit: November 06, 2016, 01:13:05 am by felaugmar »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Transform - Oriented Rectangle
« Reply #5 on: November 06, 2016, 12:06:49 am »
All pixels inside a transformed rectangle? S.A.T..
You could test a grid (to match the pixels) to see if they are inside the rectangle, outside the rectangle or contain an edge. You might only need line-crosses-line tests for this.

A simple but slow way would be to render to a render texture, copy to image, and test the pixels ;)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything