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

Author Topic: [SOLVED for now]Why reducing a vertices object size is reversed at some point ?  (Read 1987 times)

0 Members and 1 Guest are viewing this topic.

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
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~

« Last Edit: April 11, 2020, 03:17:08 am by Power »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
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 ;)
Laurent Gomila - SFML developer

Power

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
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
..
..

 
« Last Edit: April 09, 2020, 10:42:23 pm by Power »

 

anything