1
Python / Re: How Can i get Started with SFML On python (Is it a bad idea?)
« on: January 11, 2021, 01:50:56 pm »
Up!
It's important for me.
Thanks
It's important for me.
Thanks
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I completely missed this! It's so simple, i was focused on "vector".std::size_t vertexCount{ VV.getVertexCount() };
for (std::size_t i{ 0u }; i < vertexCount; ++i)
{
sf::Color randomColor; // choose your random colour how you want
VV[i].color = randomColor;
}
If I sum up... you have all these quads in a single entity, but you'd like to test intersection with each of them rather than with the whole bounds of the entity?Yes exactly Mister Laurent.
So yes, obviously you should test each quad. This is possible, you have the coordinates of the 4 vertices of each quad, as well as the transform. From that you can either get an AABB for each quad, using code similar to what we said previously, or transform each vertex and perform a more precise test against a custom concave shape (using the separate axis theorem -- Google it).
..I had a very very hard time trying to try to use the sf::sprite getglobal bounds idea. Also i moved to another method, and removed "sf::sprite" from the function you suggested and tried what follows (it was supposed to be posted in a different post but i got an error while posting)
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 classclass VertexFun : public sf::Transformable , public sf::DrawableAnd the function would be :
{private:
sf::VertexArray V;
...}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.0
And 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);The bounds are the same.
if(up==1)
{
shape1.move(0,-10);
cout << " left top width height : " << aa << " " << bb << " " << cc << " " << dd << " " << endl;
}
___
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
The position is changed with sf::Transformable::setPosition. The bounds are given by sf::VertexArray::getBounds(). How would these two things interact with each other without you doing something? How would you get a changing bounding rect magically without doing anything in your class?Very interesting! After reading your answer i tried "doing something" to changes the 4 variables defining the FloatRect obtained through getBounds(), so i did the following :
sf::VertexArray::getBounds() simply returns the min/max of the vertices' coordinates. If you never change them, then the bounding rect will never change as well.
On the other hand, changing the position changes the translation components inside sf::Transformable, and in result, modifies the entity's transform (getTransform()).
Now... after correctly understanding all that stuff, how to write a getGlobalBounds() function that works similarly to SFML entities' getGlobalBounds()? Simply by transforming the vertex array bounds by the entity's transform. And taking the bounding rect of the result.
I really think you're going too fast. You're trying complicated stuff (it is!) without having a solid background (you thought it was caused by the "const" keyword, which doesn't make any sense).True, since i understood how to inherit from the Transformable class i felt i can do anything.. and tried to do anything. Yes i am moving too fast, that's becuase i feel i am being too slow
Can't you work with SFML entities directly, until you understand SFML better? Why do you create your own entity class? What are you trying to achieve, what's your final goal?
How much time have you spend research each topic?I always assume someone who has done it all, would love to share his experience.. something like that. But you are true i did not search a lot yet, i was just excited and tried and anticipate the informations. I will see when the time comes i guess.![]()
I) I think there are tons of guides and articles on how to release a game on the play store.
II) There's obviously no silver bullet for advertising, otherwise everyone would just do that.
Public inheritance is not a solution here -- as you noticed, it brings more problems than solutions.
What's the problem with this?class VertexClass
{
sf::FloatRect getBounds() const {return m_geometry.getBounds();}
sf::VertexArray m_geometry;
}