Is this the result you want? I'm not sure why you're 'checking' from PI to -PI actually so I'm unsure if this is exactly what you want..
#include <SFML/Graphics.hpp>
#include <cmath>
inline float angle(sf::Vector2f v)
{
return std::atan2(v.y, v.x);
}
inline std::vector<sf::Vector2f> getCirclePoints(float angle)
{
std::vector<sf::Vector2f> ret;
const int maxpts = 10;
const float spread = 1.f;
const float radius = 200.f;
for(int i = 0; i < maxpts; ++i)
{
const float a = (angle - spread / 2.f) + (i * spread) / (maxpts - 1);
ret.push_back(radius * sf::Vector2f(std::cos(a), std::sin(a)));
}
return ret;
}
int main()
{
sf::RenderWindow app(sf::VideoMode(800u, 600), "cricl");
app.setFramerateLimit(60);
const sf::Vector2f mid = sf::Vector2f(app.getSize()) / 2.f;
while(app.isOpen())
{
sf::Event eve;
while(app.pollEvent(eve))
if(eve.type == sf::Event::Closed)
app.close();
app.clear();
sf::VertexArray arr(sf::LinesStrip);
const sf::Vector2f mpos = app.mapPixelToCoords(sf::Mouse::getPosition(app));
arr.append(sf::Vertex(mid));
for(sf::Vector2f v : getCirclePoints(angle(mpos - mid)))
arr.append(sf::Vertex(mid + v));
arr.append(sf::Vertex(mid));
app.draw(arr);
app.display();
}
}
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();