Rotation code isn't working

1
2
3
4
5
6
7
8
9
  sf::Vector2f delta;
	delta.x = sf::Mouse::getPosition(Window).x - getPosition().x;
	delta.y = sf::Mouse::getPosition(Window).y - getPosition().y;

	float rotation = atan2(delta.y, delta.x);
	rotation = (rotation * PI) / 180;


	rotate(rotation);


pls help it just randomly rotates around.
Last edited on
Rotations in 3D are done with rotation matrix. You have to have 3 Euler's angles defined (rotations around axis Z, then Axis Y and finally axis X). There are other variants. One of the sources is here:

http://en.wikipedia.org/wiki/Rotation_matrix

float rotation = atan2(delta.y, delta.x);
rotation = (rotation * PI) / 180;

The second statement here is conversion of degrees to radians. It seems you already did it in the first statement. The result of the first statement must be in radians.
Last edited on
closed account (D80DSL3A)
It may be that you've converted the angle wrong.
atan2 returns the angle in radians whereas the SFML functions work with degrees, so your conversion is backwards.
Does rotation = (rotation * 180) / PI; work any better?
No, that makes it violently rotate. I'm really confused on why this is not working. This is apart of a big project but nothing should be interfering with this part.
Topic archived. No new replies allowed.