61
Graphics / Re: A total of 7 questions
« on: April 01, 2020, 11:53:29 am »I understand, and i actually think i have found an old post of yours recommanding users to write multiple posts instead of having one and reviving each time .QuoteI don't want to make a post for every question, maybe i should?Let's think about it. What's the difference with you opening 7 different posts, and 7 different users opening 1 post each? None, both are fine. Or, imagine that you had 1 problem per month during 7 months, you wouldn't have the silly idea to edit the same post to add them all to it everytime.
On the other hand, mixing unrelated questions in a single post makes it hard to:
- find relevant information when finding your post through the search engine
- read all that stuff (I personally gave up)
- reply to a single question
- follow 7 different discussions mixed together, after some time passes and replies are posted
Definitely the worst idea ever. I don't know why so many people think it's "bad" to open multiple posts
The reason i found it useful to put many questions in one topic, is because i saw that few points were related (the rotation part, and then the use of matrix on transformable (which is not found in the tutorial)).
If you could read only one thing is why is there a "sf::Uint8" SFML class, hence the "sf::", that cannot be found on this list? https://www.sfml-dev.org/documentation/2.5.1/annotated.php (it would have been useful for me or other "new comers".
Will try to make separate posts whenever the questions are not related.
1)Oh i see so that's what i was missing. Ok so let's say i have understood the effect of each rotation matrix/linear transformation, how could i use it then? Let's i have this one :
These can explain it much better than I can:
https://en.wikipedia.org/wiki/Matrix_(mathematics)
https://en.wikipedia.org/wiki/Matrix_(mathematics)#Linear_transformations
https://en.wikipedia.org/wiki/Rotation_matrix
[-1 0]
[0 1]
Which is a Reflection through the vertical axis or wichever matrix containing cos and sin, should i read more to know how to use them? i can't find an example of a code using a matrix transformation (puting aside which matrix you are using, just how can it be used once you got your matrix).
Quote
2)Oh delightful, it seems to be working :
Yes, it's possible.
Rotation is always around the object's origin.
You can set O's origin to the offset between O and R and then set O's position to the same as R. O's origin will offset the visual position of O but all rotation will go around R.
Since they (O and R) seem to be 300 apart in your example, O's origin would be (0, 300).
..
int rot=10;
..
if(event.key.code==sf::Keyboard::T)
{
O.setOrigin(R.getPosition()-O.getPosition());
O.setPosition(R.getPosition());
O.rotate(rot%360);
rot=rot+10;
}
..
..
window.draw(R);
window.draw(V);
window.draw(O);
...
Result :int rot=10;
..
if(event.key.code==sf::Keyboard::T)
{
O.setOrigin(R.getPosition()-O.getPosition());
O.setPosition(R.getPosition());
O.rotate(rot%360);
rot=rot+10;
}
..
..
window.draw(R);
window.draw(V);
window.draw(O);
...

Note : Only at the second rotation, that O makes it close to R
Note 2 : it seems to be rotating around the origin of R indeed, and not around the center of R, i am pretty sure that fixable.
Quote
3)Understood.
Not sure I understand the question.
You can have different coloured triangles in a single vertex array but not in a standard SFML shape (without using a texture).
Quote
4)Oh i see so the the Uint8 Pixels variable is an array containing the values for each pixel of the image taking in count all four componenots, meaning if i had a coloured image with a size of (4,5) that would mean the Uint8 variable would be an array of 20x4 length.
sf::Uint8 is an unsigned 8-bit integer.
Your example is an array of those necessary for an image - basically an array of bytes. Each colour component is an 8-bit value - 0-255.
Although, I would suggest that there is an error; it should be multiplied by 4, not 1, for the four components - one byte each.
So now, i guess it's time to change every pixel with some kind of "for" and browse the pixels you want to change, one by one or a range by range..?
And then at the end do :
tex1.update(pixels);
?Would be great to see an example of this.
Quote
5)Yes i just did:
Have you tried this without the difference? Does it work? Is it the same?
MyEntity(float NewPointcount) : PC(NewPointcount)
{
sf::VertexArray Vex(sf::TriangleStrip, PC);
const sf::Color colorArray[5]={sf::Color::Cyan, sf::Color::Blue, sf::Color::Green, sf::Color::Red, sf::Color::Yellow };
srand(time(nullptr)); // use current time as seed for random generator
for (int n=0; n != PC; ++n)
{
int random_variable2 = rand()%400+1;
int random_variable3 = rand()%500+300;
Vex[n].position = sf::Vector2f(random_variable2+random_variable3, random_variable2/2);
Vex[n].color = colorArray[rand()%5];
}
};
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the entity's transform -- combine it with the one that was passed by the caller
states.transform *= getTransform(); // getTransform() is defined by sf::Transformable
// apply the texture
states.texture = &m_texture;
// you may also override states.shader or states.blendMode if you want
// draw the vertex array
target.draw(m_vertices, states);
}
sf::VertexArray m_vertices;
sf::Texture m_texture;
int PC;
};
and {
sf::VertexArray Vex(sf::TriangleStrip, PC);
const sf::Color colorArray[5]={sf::Color::Cyan, sf::Color::Blue, sf::Color::Green, sf::Color::Red, sf::Color::Yellow };
srand(time(nullptr)); // use current time as seed for random generator
for (int n=0; n != PC; ++n)
{
int random_variable2 = rand()%400+1;
int random_variable3 = rand()%500+300;
Vex[n].position = sf::Vector2f(random_variable2+random_variable3, random_variable2/2);
Vex[n].color = colorArray[rand()%5];
}
};
private:
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
// apply the entity's transform -- combine it with the one that was passed by the caller
states.transform *= getTransform(); // getTransform() is defined by sf::Transformable
// apply the texture
states.texture = &m_texture;
// you may also override states.shader or states.blendMode if you want
// draw the vertex array
target.draw(m_vertices, states);
}
sf::VertexArray m_vertices;
sf::Texture m_texture;
int PC;
};
MyEntity ME(6);
..
..
window..draw(ME);
window.display();
Nothing...
..
window..draw(ME);
window.display();
Reminder here is the code that works well in the same main :
int N;
cout << endl << " choose N : (below 26000) " << endl;
cin >> N;
sf::VertexArray Vexy(sf::TriangleStrip,N);
srand(time(nullptr)); // use current time as seed for random generator
for(int i;i!=N;i++)
{
int random_variable2 = rand()%400+1;
int random_variable3 = rand()%500+300;
Vexy[i].position = sf::Vector2f(random_variable2+random_variable3, random_variable2/2);
Vexy[i].color = colorArray[rand()%5];
}
...
window.draw(Vexy);
cout << endl << " choose N : (below 26000) " << endl;
cin >> N;
sf::VertexArray Vexy(sf::TriangleStrip,N);
srand(time(nullptr)); // use current time as seed for random generator
for(int i;i!=N;i++)
{
int random_variable2 = rand()%400+1;
int random_variable3 = rand()%500+300;
Vexy[i].position = sf::Vector2f(random_variable2+random_variable3, random_variable2/2);
Vexy[i].color = colorArray[rand()%5];
}
...
window.draw(Vexy);
Quote
6)Those vertices don't have to BE rectangular. You meant? i Guess.
tu and tv are arbitrary values to reference the tile within the texture and are used to set the texture co-ordinates for that tile.
t is for texture. u and v are common co-ordinate variables for texture (XYZ for space, UVW for texture)
In the tilemap example, it uses a vertex array with the quad primitive. Every one of those quad primitive requires four vertices to define its corners. Those vertices don't have to rectangular.
Quote
7)Ah indeed you got me there, it's a great example, i enjoyed trying to understand it, being new, yeah that was my mistake.
Firstly, your cyan lines are incorrect. They should point to the same place as the red lines.
The "position" is where they are drawn/shown. You can see that the left row are all x = 0 and that y steps up by the height of the tile (i.e. in 32 increments).
The "coordinates TEX" is where in the texture that tile is using. You can see all the tiles that have grass all have the same co-ordinates. Each different tile has a different value (its location in the texture/tileset image).
Hope some of that helps
Yes Your help is MUCH APPRECIATED. Thank you so much.