[SFML][Vector] Problem with Polar and Cartesian Coordinates convertion

In a testing SFML project of mine, I've made 3 sf::CircleShape's: a big one, 2 small ones. The 2 small ones are supposed to be moving slowly around the center of the big one about 60px. They do move around but too fast. There must be something wrong with my calculations.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	int direction = 0;

	sf::CircleShape ball(50); //the big one, radius: 50
	ball.setPosition(100, 100); //position: 100, 100
	ball.setFillColor(sf::Color(0, 165, 235));
	ball.setOutlineThickness(2);
	ball.setOutlineColor(sf::Color::Black);

	sf::CircleShape arm[2]; //2 small ones
	for (int i = 0; i < 2; i++) {
		arm[i].setRadius(10); //radius: 10
		arm[i].setFillColor(sf::Color(0, 165, 235));
		arm[i].setOutlineThickness(2);
		arm[i].setOutlineColor(sf::Color::Black);
	}

	sf::Vector2f 
		vector1, //vector from the big one's center to one of the small ones' center
		vector2(ball.getPosition() + sf::Vector2f(ball.getRadius(), ball.getRadius())), //location of the big one's center point
		vector3(arm[0].getRadius(), arm[0].getRadius()); //the center points of the 2 small ones move around not position


	while (Window.isOpen()) { // the loop
		sf::Event Event;
		if (Window.pollEvent(Event)) {
			if (Event.type = sf::Event::KeyPressed) {
				if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) direction++;
				else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) direction--;
			} //move the 2 small ones around with left and right arrow keys
		}
		if (direction == 360) direction = 0;
		else if (direction == -1) direction = 359;


		// I think there must be something wrong here
		vector1.x = (ball.getRadius() + ball.getOutlineThickness() + 5) * cos(direction);
		vector1.y = (ball.getRadius() + ball.getOutlineThickness() + 5) * sin(direction);

		arm[0].setPosition(vector2 + vector1 - vector3);
		//location center of the big one + vector to one of the small oness center - vector to one of the small ones' (0, 0) point
		arm[1].setPosition(vector2 - vector1 - vector3);
	}
Just a quick guess: you think that the arguments for sin and cos are degrees. They are radians. So cos(direction) should be replaced by cos(direction*M_PI/180.) Same for sin.
I #include d math.h but the compiler is complaining
identifier 'M_PI' is undefined


Edit: Nevermind
Thanks. It works
Last edited on
Topic archived. No new replies allowed.