Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: View::Rotate, not there, how to simulate it?  (Read 4164 times)

0 Members and 1 Guest are viewing this topic.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
View::Rotate, not there, how to simulate it?
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
View::Rotate, not there, how to simulate it?
« Reply #1 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.
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
View::Rotate, not there, how to simulate it?
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
View::Rotate, not there, how to simulate it?
« Reply #3 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
Laurent Gomila - SFML developer

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
View::Rotate, not there, how to simulate it?
« Reply #4 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
View::Rotate, not there, how to simulate it?
« Reply #5 on: December 02, 2008, 07:51:32 am »
Of course ;)
Code: [Select]
Scene.SetCenter(width / 2, height / 2);
Laurent Gomila - SFML developer

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
View::Rotate, not there, how to simulate it?
« Reply #6 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.  :?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
View::Rotate, not there, how to simulate it?
« Reply #7 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)?
Laurent Gomila - SFML developer

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
View::Rotate, not there, how to simulate it?
« Reply #8 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?