SFML community forums

Help => Graphics => Topic started by: Power on April 09, 2020, 06:56:29 pm

Title: [SOLVED for now]Why reducing a vertices object size is reversed at some point ?
Post by: Power on April 09, 2020, 06:56:29 pm
Hello again,
I made a function to reduce or contract the size of a shape made of vertices :
void contract(sf::VertexArray &V,float ExpandValue,char item,int NumberOfVertices)

It seems to be working, but i noticed the shape start to expanding after it has reached a size of 0 , like this :
https://gfycat.com/fr/illfatedesteemedenglishpointer

Any idea about this phenomenon?
The window is a (800,800).

Thanks
P~

Title: Re: Why reducing a vertices object size is reversed at some point ? (it expands)
Post by: Laurent on April 09, 2020, 07:08:34 pm
Without seeing your code, what kind of answer do you expect? I have no idea what's in that function, because a simple setScale does the job. And yes, negative scales result in a symmetry. Just think about what a scaling transformation does, and it should be obvious ;)
Title: Re: Why reducing a vertices object size is reversed at some point ? (it expands)
Post by: Power on April 09, 2020, 10:36:46 pm
Yes here it is
void contract(sf::VertexArray &V,float ExpandValue,char item,int NumberOfVertices)
{
    if (V.getVertexCount()==4)
  {
V[0].position.x=V[0].position.x+ExpandValue; V[0].position.y=V[0].position.y+ExpandValue;
V[1].position.x=V[1].position.x-ExpandValue; V[1].position.y=V[1].position.y+ExpandValue;
V[2].position.x=V[2].position.x-ExpandValue; V[2].position.y=V[2].position.y-ExpandValue;
V[3].position.x=V[3].position.x+ExpandValue; V[3].position.y=V[3].position.y-ExpandValue;

NewXCenterShape=V[1].position.x-V[0].position.x;
NewYCenterShape=V[2].position.y-V[1].position.y;

...
...
 
It's the part about the 4 vertices in the center (the rectangle)

And then called the function :
sf::VertexArray CenterObj(sf::Quads,4);
    CenterObj[0].position=sf::Vector2f(300,300);
    CenterObj[1].position=sf::Vector2f(400,300);
    CenterObj[2].position=sf::Vector2f(400,400);
    CenterObj[3].position=sf::Vector2f(300,400);
    CenterObj[0].texCoords = sf::Vector2f(80.f, 76.f);
    CenterObj[1].texCoords = sf::Vector2f(122.f, 76.f);
    CenterObj[2].texCoords = sf::Vector2f(122.f, 122.f);
    CenterObj[3].texCoords = sf::Vector2f(80.f, 122.f);

...
...
if(event.type==sf::Event::KeyPressed&&event.key.code==sf::Keyboard::C)
            {
                float ContactValue=1;
               contract(CenterObj,ContactValue,'e',4); //here the char variable is not important, it is not used, 'e' can be replaced
..
..