SFML community forums

Help => Window => Topic started by: heishe on August 27, 2008, 01:54:04 am

Title: View::Rotate, not there, how to simulate it?
Post 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
Title: View::Rotate, not there, how to simulate it?
Post by: Laurent on August 27, 2008, 08:22:44 am
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.
Title: View::Rotate, not there, how to simulate it?
Post by: heishe on August 30, 2008, 12:54:41 am
please do it fast, im not good enough at graphics programming to implement what you suggested myself.
Title: View::Rotate, not there, how to simulate it?
Post by: Laurent on August 30, 2008, 08:51:22 am
Code: [Select]
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
Title: View::Rotate, not there, how to simulate it?
Post by: model76 on December 02, 2008, 04:13:08 am
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!
Title: View::Rotate, not there, how to simulate it?
Post by: Laurent on December 02, 2008, 07:51:32 am
Of course ;)
Code: [Select]
Scene.SetCenter(width / 2, height / 2);
Title: View::Rotate, not there, how to simulate it?
Post by: model76 on December 03, 2008, 02:16:20 am
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.  :?
Title: View::Rotate, not there, how to simulate it?
Post by: Laurent on December 03, 2008, 07:46:35 am
The view is always supposed to rotate around its center. Can you show your code (or better: a minimal example which reproduces your problem)?
Title: View::Rotate, not there, how to simulate it?
Post by: model76 on December 04, 2008, 08:10:20 am
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:
Code: [Select]

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?