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

0 Members and 1 Guest are viewing this topic.

#### Power

• Jr. Member
• Posts: 70
##### [SOLVED for now]Why reducing a vertices object size is reversed at some point ?
« 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

The window is a (800,800).

Thanks
P~

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

#### Laurent

• Hero Member
• Posts: 32504
##### Re: Why reducing a vertices object size is reversed at some point ? (it expands)
« Reply #1 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
Laurent Gomila - SFML developer

#### Power

• Jr. Member
• Posts: 70
##### Re: Why reducing a vertices object size is reversed at some point ? (it expands)
« Reply #2 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 :
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 »