Hello, so here is the shape i made, and my goal ultimately is to be able to test the intersections between some entity and the elements of this image specifically (it means : not the rectangle surrounding the shape).
Its construction follow the tilemap example, its has a vertexArray as an attributes which is resized to match the size of the total numbers of vertices needed to make the shape in the image above. So total numbers of vertices is :
1) +4 (for the rectangle in the middle)
2) +(6*4) for the diamond shapes on every side.
3) multiply line 2 by 4.
Totat vertices = 4+(6*4)*4= 100.
I proceed to construct the vertices with a function member of the class
class VertexFun : public sf::Transformable , public sf::Drawable
{private:
sf::VertexArray V;
...}
And the function would be :
public :
bool VertexShapeQuad(const std::string& address, sf::Vector2f centerOfVertex, sf::Vector2f Dimensions, sf::Vector2f halfRadius, int NumberOfWings, int NumberOfElements )
{...} /// i dont need the first parameter, it's just in case i want to use a texture
Final result is shown at the beginning of this post.
VertexFun shape1;
shape1.VertexShapeQuad("data/tilemap.png",sf::Vector2f(400,400),sf::Vector2f(30,30),sf::Vector2f(10,10),4,6);
....
window.clear(sf::Color::White);
window.draw(shape1);
window.display();
Okay now i am taking the advice i was given lastly here :
https://en.sfml-dev.org/forums/index.php?topic=27161.0And i am trying to get the global bounds of the vertexArray:
i implemented this function member :
sf::FloatRect getGlobalBounds()
{
return getTransform().transformRect(V.getBounds());
}
And when using it in the main :
sf::FloatRect ff;
ff=shape1.getGlobalBounds();
int aa,bb,cc,dd;
aa=ff.left;bb=ff.top;cc=ff.width;dd=ff.height;
cout << " left top width height : " << aa << " " << bb << " " << cc << " " << dd << " " << endl;
I find that it has what i presume the bound of the rectangle made by the whole shape :
AND, when i use a moving function:
up = (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) ? 1 : 0);
if(up==1)
{
shape1.move(0,-10);
cout << " left top width height : " << aa << " " << bb << " " << cc << " " << dd << " " << endl;
}
The bounds are the same.
___
To the questions :
1) I think i should have a member function (sf::FloatRect getGlobalBounds()) that applies to each little structures (the rectangle + diamonds) i made, and then proceed to test them ALL, to be able to check the "intersection" of an entity with my vertexclass?
But IS THAT POSSIBLE? Since i have only one "VertexArray" in my Class? The GetBounds applies to the wholes points of the vertexArray and not individually for each 4 vertices.... (reminder : all the elements in the image are 4-vertices shapes inside ONE vertexAray)
2) Any other idea how to do it?
Thanks