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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Offam1992

Pages: [1]
1
Graphics / Re: How the heck does origin work? Extremely confused.....
« on: February 27, 2019, 08:40:19 pm »
If you're setting the origin to the bottom of the smaller rectangle and want both origins to be in the same place (i.e. the bottom of the small one touching the top of the larger one) then both rectangles should have the same position.

I see. So let's say I want the same result, but the starting square has it's origin in the center. How would I go about doing it?


Quote
Is there a way to force apply the transformations immediately?
Yes. Bypass the entity's transform with your own transform (sf::Transform). sf::Transform is lower level, it's actually a thin wrapper on top of a 4x4 matrix so you can build whatever you want with it.

sf::Transform transform;
transform.translate(x, y); // first translate
transform.rotate(a); // then rotate
// ...
window.draw(entity, transform);

Then, remember that everything based on the entity's transform (local/global bounds for example) won't be right since it will use the entity's transform and not yours.

Thanks. Unfortunately I won't be able to use that method as I need to be able to use the entity's transform.

2
Graphics / Re: How the heck does origin work? Extremely confused.....
« on: February 27, 2019, 07:31:21 pm »
I see. Then what is wrong with the coded I posted above? Is it just the issue of transformations not being applied until it's drawn?

3
Graphics / Re: How the heck does origin work? Extremely confused.....
« on: February 27, 2019, 06:59:43 pm »
The move function is a shortcut for setPosition, and position is also based on the local origin. And remember that transformations are not applied immediately, but rather in a fixed order when the entity is drawn. So I think your assumptions about the final position are wrong.

I see. So to solve the first problem, always do moves and setPositions before changing the origin?

How could I solve the second problem? Is there a way to force apply the transformations immediately?

4
Graphics / How the heck does origin work? Extremely confused.....
« on: February 27, 2019, 05:10:48 pm »
So I'm trying to work with the origin, and it makes no sense to me at all. Here's some simple code I wrote to play around with the origin:


        sf::RenderWindow window(sf::VideoMode(1200, 800), "Window");

        sf::RectangleShape square(sf::Vector2f(200, 200));
        square.setPosition(500, 600);

        auto smallSquare = square;
        smallSquare.move(0, -square.getSize().y);
        smallSquare.setOrigin(0, square.getSize().y);
        smallSquare.scale(0.5, 0.5);

        while (window.isOpen())
        {

                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                window.draw(square);
                window.draw(smallSquare);
                window.display();
        }

What I expect this to do is
1) Draw a 200x200 square at the center bottom of the screen
2) Make a copy of that square called smallSquare
3) Move the smallSquare upwards by the height of the square
4) Set smallSquare's origin to it's bottom left corner, instead of top left.
5) Scale the smallSquare to 0.5 around it's new origin

So the result should be a 200x200 square at the center bottom, with a 100x100 square on top of it on it's left side. Sort of like a blocky lowercase b shape.

Instead what I get is

(click to show/hide)

Why is this happening? What's wrong with my assumptions of how the origin works?

Pages: [1]