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

Author Topic: Origin Scaling  (Read 1957 times)

0 Members and 1 Guest are viewing this topic.

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Origin Scaling
« on: October 07, 2012, 04:23:29 pm »
I'm unsure as to whether this was intentional or not, but when scaling anything in SFML 2, it also scales the origin. This for example -
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Origin Scaling");
    sf::RectangleShape rectangle;
    rectangle.setSize(sf::Vector2f(100, 50));
    rectangle.setScale(0.25, 0.25);
    rectangle.setOrigin(-300, -300);

    while (1)
    {
        window.draw(rectangle);
        window.display();
    }
}
 
will not move the rectangle 300 pixels away from the left and 300 from the top, but rather a quarter of that.
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Origin Scaling
« Reply #1 on: October 07, 2012, 04:46:42 pm »
If the rectangle is initially 300 pixels away from the transformation origin, and you apply a scaling of 0.25, its final position is 300 * 0.25 away from the origin. That's what scaling does, what else did you expect?
Laurent Gomila - SFML developer

Jalfor

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Re: Origin Scaling
« Reply #2 on: October 07, 2012, 04:52:42 pm »
I just didn't expect it to affect the origin. Anyway, I fixed it now by dividing origin by the scale when getting the origin and multiplying it by the scale when setting it.
If a picture tells 1000 words, then a YouTube video clearly tells 1000000 making a YouTube video obviously a larger work than the Lord Of The Rings, or some other massive novel. Thus are the laws of YouTube videos.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Origin Scaling
« Reply #3 on: October 07, 2012, 05:56:48 pm »
It doesn't affect the origin. The origin hasn't moved after scaling, it's the top-left corner of the rectangle which has moved closer to the origin.

The scale formula is simple: final_point = source_point * scale. If the top-left corner is at (300, 300), after scaling it ends up at (300 * 0.25, 300 * 0.25) from the origin.

Quote
Anyway, I fixed it now by dividing origin by the scale when getting the origin and multiplying it by the scale when setting it.
So your own "origin" is at a fixed distance from the top-left corner, and moves in the absolute coordinate system when you scale your entity. This is a strange way to handle it. Why do you need that? Can't you just leave the origin to the top-left corner, and use the position to offset the rectangle?
Laurent Gomila - SFML developer

 

anything