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 - timrh

Pages: [1]
1
Graphics / Re: Drawing a circle segment
« on: November 22, 2017, 08:37:15 pm »
Now I see the point of your solution, it's better than mine.
Thanks for the help!

2
Graphics / Re: Drawing a circle segment
« on: November 21, 2017, 05:31:52 pm »
I tried to write it one more time. And it works now.

And this was my idea:
1.In do while loop, from temp angle variable to segment angle,
2.Get mouse to radius center angle by atan2,
3.Set point of segment, as product of rotation around circle center, where angle is equal to temp angle variable + mouse to radius center angle - segment angle / 2, * radius.

                gameWindow.clear();
        sf::VertexArray arr(sf::LinesStrip);

        float segmentAngle{degToRad(60)};
        float radius{100};
        sf::Vector2f radiusPos{ gameWindow.getView().getCenter() };

        unsigned circlePoints{10};
        float angle{ 0 };

        arr.append(radiusPos);
        do
        {      
                sf::Vector2f mRelP //get relative mouse position
                {
                        sf::Mouse::getPosition(gameWindow).x - radiusPos.x,
                        sf::Mouse::getPosition(gameWindow).y - radiusPos.y
                };

                float mouseAngle{ atan2(mRelP.y, mRelP.x) }; //get angle between mouse and circle center

                sf::Vector2f p
                {                      
                        cos(angle + (mouseAngle - segmentAngle / 2)) * radius, //position = cos(angle + lookAngle) * rad
                        sin(angle + (mouseAngle - segmentAngle / 2)) * radius  //position = sin(angle + lookAngle) * rad               
                };

                p += radiusPos;
                arr.append(p);

                angle += segmentAngle / circlePoints;

        } while (angle < segmentAngle);

        arr.append(radiusPos);

        gameWindow.draw(arr);
        gameWindow.display();
 

3
Graphics / Re: Drawing a circle segment
« on: November 21, 2017, 02:06:58 pm »
This is exactly what I wanted...

Can you tell me the secret behind getting a? I know that is angle of segment point, but what is spread? And how exactly it works?

Code: [Select]
const float a = (angle - spread / 2.f) + (i * spread) / (maxpts - 1);

4
Graphics / Drawing a circle segment
« on: November 20, 2017, 07:07:43 pm »
I want to draw circle segment, segment will be drawn dependent on mouse position, in this image you can see what I want to achieve:

https://imgur.com/a/HKiHc

as you can see, circle segment is looking to mouse, I had been trying to do it alone, but I can't.

This was my idea:

my basic circle draw code:

Code: [Select]
gameWindow.clear(sf::Color{ 60, 60, 60 });

float angle = PI;
float radius = 50;
unsigned points = 50;

VertexArray circle(LinesStrip, 0);
Vector2f orgin = gameWindow.getView().getCenter();

do
{
Vector2f pointPos = { cos(angle) * radius, sin(angle) * radius };
pointPos += orgin;

circle.append(pointPos);

angle -= PI * 2 / points;

} while (angle > -PI);

circle.append(circle[0]);

gameWindow.draw(circle);
gameWindow.display();

getting angles:

Code: [Select]
alpha = atan2(mouse.y, mouse.x);
beta = alpha - alpha / 2;
gamma = alpha + alpha / 2;

as you can see I set range from PI to -PI, to have the same angle range as in atan2.
Next I wanted to check points that are in range specified by beta and gamma, and that worked, but partionally...

Because in some cases, my circle was drawed in that way:

https://imgur.com/a/N5e3b

Inverting beta and gamma not worked to me, I created conditions that were checking that beta and gamma are in range <-PI; PI>, if not, then I changed for example angles, but that not worked too.

After hour of thinking, and complicating my code, I removed it, and I think that I need help.
Please show me how can I draw circle segment in that way.
Thanks.






5
General / Drawing sprites from another thread
« on: October 17, 2016, 12:43:26 am »
Hello i'm new in SFML, I want to draw sprite from another thread so i created thread:

void DrawMap(RenderWindow * render_window)
{
        while (true)
        {
                for (int y = 0; y < 5; y++)
                {
                        for (int x = 0; x < 10; x++)
                        {
                                face_img.setTextureRect(IntRect(rand() % 3 * 32, 0, 32, 32));
                                face_img.setPosition(x * 64, y * 64);
                                render_window->draw(face_img);
                        }
                }
                Sleep(100);
        }
}

In main() i have created RenderWindow:

        RenderWindow render_window(VideoMode(640, 320), "Map Generator", Style::Close + Style::Titlebar);


And I started the thread:
        Thread thread(&DrawMap, &render_window);
        thread.launch();
But nothing was drawed, i have message: "Failed to activate window's context"
Please help, and sorry I'm sure that my error is stupid but I'm new here.
Thanks!

Pages: [1]