SFML community forums
Help => Window => Topic started by: heishe on August 27, 2008, 01:54:04 am
-
If i just want to rotate the whole scene, how could I do that without setting the center and rotating every single object manually?
greetings,
heishe
-
I will probably be implemented in the next version.
To simulate it, you can create a classe inheriting from sf::Drawable and override the Render function to draw all your objects. Every transformation made to this drawable will be applied to all the objects drawn inside.
-
please do it fast, im not good enough at graphics programming to implement what you suggested myself.
-
class MyScene : public sf::Drawable
{
virtual void Render(const sf::RenderWindow& Window) const
{
// Draw your scene here with calls to Window.Draw(...)
}
}
// In your main...
MyScene Scene;
...
Scene.Rotate(45); // Rotate the entire scene
App.Draw(Scene); // Draw the entire scene
-
I was having the same problem as heishe, so I was happy to find this solution, which I have now implemented.
I do have one problem, however: The rotation happens around the scene origin, where I would like to have it around the view center.
Do you also have a solution to this?
Thank you for making SFML!
-
Of course ;)
Scene.SetCenter(width / 2, height / 2);
-
Thank you for answering!
I did as you suggested, assuming you meant the view width and height, and it works fine as long as I keep the view centered at 0, 0.
If I move the center, however, the rotation will still happen around 0, 0 -which isn't quite what I was aiming for. I was really hoping for a true rotating camera effect, regardless of position. :?
-
The view is always supposed to rotate around its center. Can you show your code (or better: a minimal example which reproduces your problem)?
-
Oh, right, I see now that we have been talking past each other..
When I said "view" I meant "sf::View", which cannot rotate. Yet... :wink:
If I move the position of the center of the sf::View, the center of the MyScene object, and thus the center of rotation, will stay the same, and the rotating camera effect will break.
If I just set the center of the MyScene object to the center of the sf::View, everything I render in the MyScene will move with the camera, and thus will not appear to move at all.
So I guess I could do something like:
class MyScene : public sf::Drawable
{
virtual void Render(const sf::RenderWindow& Window) const
{
// Draw your scene here with calls to Window.Draw(...)
}
}
// In your main...
MyScene Scene;
sf::View Camera;
// Move the camera
float newX = 100.f;
float newY = -100.f;
Camera.setPosition( newX, newY );
Scene.setCenter( newX, newY );
Scene.setPosition( -newX, -newY );
...
Scene.Rotate(45); // Rotate the entire scene
App.Draw(Scene); // Draw the entire scene
But isn't there a prettier way?
I suppose I could incorporate the camera into the MyScene class.. How would you do it?