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

Show Posts

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.


Messages - Power

Pages: [1] 2 3 ... 5
1
Up!
It's important for me.

Thanks

2
Python / How Can i get Started with SFML On python (Is it a bad idea?)
« on: January 10, 2021, 04:29:35 pm »
Hello,

I am familiar with SFML, C++ CodeBlocks user,
I am starting a new project that require Python and i would like to use all the Graphical option SFML offer (within my Python),

How get i started? Do i have to add the libraires for SFML the way i did with CodeBlocks ? (https://www.sfml-dev.org/tutorials/2.5/start-cb.php) Or Do i have to do anything else?

Thanks

3
General / Re: I am back after a long pause, i need to reconfigure CodeBlocks
« on: September 27, 2020, 09:17:30 pm »
Found the solution :
I had added the "s" type library and the "non s" library aswell, i removed one and kept "\libsfml-graphics-d.a" and all 50 errors dissapeared.

4
Hello,
I lost one hard drive called "D:\" last month, it has all my codes, i could try to get my files back but as for now the hard drive is dead.
It has also my "project templates".

I just reconfigured the libraries ( https://www.sfml-dev.org/tutorials/2.5/start-cb.php) and tried to run the test code :
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}


I get this error message :
(image)


Could someone help?
I tried to check on all codeblocks parameters and did not find anything related to "D:\", then i tried to check my windows variables (PATH stuff), same thing i did not see anything related SFML.
Thanks


5
Very comprehensive and complete answer, thank you.
I was aware "rand" was not good, that it had something to do with the processor clock etc.. but i did not bother searching for alternatives, i will check "random".

Quote
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;
}
I completely missed this! It's so simple, i was focused on "vector".
Thanks again!

6
Hello,
I took a pause from SFML a bit, but i came back to do something briefly.
I wanted to modify colors of a vertexArray randomly.
1. VertexArray is already declared, the vertices positions are known.
2. The function takes the VertexArray as a parameter and modify the vertices colors. Its a "ref".

bool VertexColorREAL(sf::VertexArray &VV )
        {

        std::size_t cnt=VV.getVertexCount(); ///count
        if(cnt==4)
        {
                sf::Color &c0=VV[0].color;
                sf::Color &c1=VV[1].color;
                sf::Color &c2=VV[2].color;
                sf::Color &c3=VV[3].color;

            c0.r = rand() % 255+ 0;
            c0.g = rand() % 255+ 0;
            c0.b = rand() % 255+ 0;
            c1.r = rand() % 255+ 0;
            c1.g = rand() % 255+ 0;
            c1.b = rand() % 255+ 0;
            c2.r = rand() % 255+ 0;
            c2.g = rand() % 255+ 0;
            c2.b = rand() % 255+ 0;
            c3.r = rand() % 255+ 0;
            c3.g = rand() % 255+ 0;
            c3.b = rand() % 255+ 0;
        }
        if(cnt==3)
        {
//..
        }

        return true;
        }
 

3. The function checks the number of vertices (if count==4).. etc

Is it possible to work with push_back, to modify only the colors ? I am trying to write something like this :

bool VertexColorREAL(sf::VertexArray &VV )
        {
            vector<sf::Vertex> vertices;


            for(int i=0;i<VV.getVertexCount();i++)
            {
                &vertices.push_back(sf::Vertex(sf::Color::Black)); // obviousely ERROR
           /// I am not quite sure how to do it.
            }

 

-> I am not quite sure how to do it, i don't know if push_back can be used as a setter somehow, the only use i know of is as a constructor, something like this :
vector<sf::Vertex> vertices; ///  (VECTOR  std c++)
    vertices.push_back(sf::Vertex(sf::Vector2f(110.f,110.f),sf::Color::Black));
    vertices.push_back(sf::Vertex(sf::Vector2f(210.f,110.f),sf::Color::Yellow));
    vertices.push_back(sf::Vertex(sf::Vector2f(210.f,210.f),sf::Color::Blue));
 
Is there a way to turn around this as a color setter instead of constructors?
Thanks

7
Okay thank you for the answer.
Feedback : I feel there should be a whole tutorial about the physics and all that you described.

Or at least 2 sentences in the "Bounding boxes" section of the "Position, rotation, scale: Transforming entities" tutorial, mentioning the necessity of studing specific interactions outside of the tutorials when it comes to non-rectangular entities. Because at first i imaging being able to test collisions of any kind of entity prociving i could use SFML functions such as getGlobalBounds() etc.. someone might have the same assumption.

8
I forgot to add the image for the entity of the question number 2:

9
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 found it : https://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169 OOh myy this seems to be like quite a read that i can probably complete, with time.

Two quick questions though, please.

1) Let's say i made the same shape but with regular sf::RectangularShape 's. And i used "rotate" to make the "diamonds" in the side.

Will getGlobalBounds() for the rotated RectangularShapes (the diamonds) give me different results when it has been rotated and do i have to use a function similar to the one you explained (using getTransform and TransformRect) etc.. ? In any case i need the theorem you quoted to do the test boundaries right?

2)
Using rectangularShapes to make lines and make a shape like the one in this image (the entity in the upper right)
If i made it, will i be able to check the bounds of an item passing through easily? I am suspecting that getlobalBounds() will give me a very big rectangle and not the a zone describing precisely the lines i have drawn.


10
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.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);
        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

11
..
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, I am getting an error message trying to post a new post on the forum and it says : report it to the admin if it happens again, which did.
Here the content of the post so i dont lose it :
Quote
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.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);
        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

12
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.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);
        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

13
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.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);
        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

14
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.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);
        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

15
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.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);
        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

Pages: [1] 2 3 ... 5