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.


Topics - Brandy

Pages: [1]
1
Graphics / Strange behaviour of sf::Shape::SetRotation?
« on: February 09, 2009, 07:17:39 am »
I was writing some code yesterday which was just displaying a white rectangle following the mouse cursor with its orientation. This rectangle was a sf::Sprite, and therefore I set the Center to the middle of the Sprite. Then I then tried to do the same thing with a sf::Shape and created just the same rectangle again. But when I tried to apply the code for the rotation to it, the rectangle was behaving quite strange.
I really have no idea why this is not working, maybe I misunderstood some of the methods the class is offering. So here's the relevant code:

Code: [Select]
sf::Shape shape;
shape.AddPoint(300, 300); //I am aware of sf::Shape::rectangle, but I  think it should work like that anyway.
shape.AddPoint(500, 300);
shape.AddPoint(500, 500);
shape.AddPoint(300, 500);
shape.SetCenter(100,100); //Shouldn't this set the center exactly to the rectangle's middle?

//Event handling etc. is not mentioned here, please don't mention the code indent, it was kind of messed up by copy'n paste from the sourcefile.

if (input.GetMouseX() <= shape.GetPosition().x) {
shape.SetRotation  (-1 * 180 / 3.1415926535 * (atan( static_cast<double> (shape.GetPosition().y - input.GetMouseY()) / static_cast<double> (shape.GetPosition().x - input.GetMouseX()))));
} else {
shape.SetRotation  (-1 * 180 / 3.1415926535 *(atan( static_cast<double> (shape.GetPosition().y - input.GetMouseY()) / static_cast<double> (shape.GetPosition().x - input.GetMouseX()))));
}


This rotation code (any suggestions to improve it?) works just fine for sf::Sprite. But like I said, here it's messing up the whole thing.
When experimenting a bit with the values I passed to SetCenter() I noticed that the shape was seemingly displaced just about the parameters I passed to SetCenter().
What am I doing wrong?

Another little question:
When I am rotating the Shape, are the positions of the points added with AddPoint() influenced? Checking the points' coordinates made me think it wouldn't.

Pages: [1]
anything