I used trigonometric cicrcle to make ball sprite move on a circular path. It does, only thing is that the path is always moving and changing radius. Don't know if it is a float rounding error or my computer going mad, or probably a semantic error. I'd be grateful if someone took a look at code and helped my find the error.
Sry if code isn't readable. I commented only logic parts.
#include <SFML\Graphics.hpp>
#include <cmath>
int main()
{
sf::VideoMode VMode(800, 600, 32);
sf::RenderWindow Window(VMode, "Test");
sf::Texture Ball;
if (!Ball.LoadFromFile("ball.png"))
return 1;
double speed = 1;//constants and start values
long double angle = 90;
const double rad = 57.2957795;
double ang = 0;
sf::Sprite ball(Ball);
ball.SetPosition(400,300);
ball.SetScale(0.1,0.1);
sf::Event Event;
while (Window.IsOpened())
{
while (Window.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
{
Window.Close();
break;
}
}
if (angle > 360)//if angle exceeds 360
angle -= 360;//reset it
angle += speed * Window.GetFrameTime();//angle in degrees
ang = angle/rad;//angle in radians
ball.Move(std::sin(ang),std::cos(ang));//move on a circular path
Window.Clear(sf::Color(255,0,0));
Window.Draw(ball);
Window.Display();
}
return 0;
}