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

Author Topic: xy rotation using transform?  (Read 2791 times)

0 Members and 1 Guest are viewing this topic.

HemoGoblin

  • Newbie
  • *
  • Posts: 6
    • View Profile
xy rotation using transform?
« on: September 09, 2012, 03:44:32 pm »
Hi there!
I was trying to implement xy rotation for my sprite. Only way i could think of was to use transforms with 3x3 rotation matrix. However the image is no longer centered (its position was set to the center of view and the origin was set to half the texture size). The question is, how to rotate it using transforms without repositioning? Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: xy rotation using transform?
« Reply #1 on: September 09, 2012, 04:12:09 pm »
What do you exactly mean with 'my sprite'? Have you written your own implementation of a sprite?
If so, have you thought about deriving from sf::Transformable?

If you're using the sf::Sprite, you can simply change the origin and make the transformation to that point.

If you want to work with a rotation matrix, you can use sf::Transform and instead of inserting the position, you use the transformation origin.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

HemoGoblin

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: xy rotation using transform?
« Reply #2 on: September 09, 2012, 04:18:48 pm »
I have this code:


#include <SFML/Graphics.hpp>


int main() {

        sf::RenderWindow Window(sf::VideoMode(1024, 600), "Test");

        sf::Texture Texture;
        Texture.loadFromFile("A.png");

        sf::Sprite Sprite(Texture);
        Sprite.setOrigin(36.0f, 36.0f);
        Sprite.setPosition(512.0f, 300.0f);

        while (Window.isOpen()) {

                sf::Event Event;
                while (Window.pollEvent(Event)) {

                        switch (Event.type) {

                                case sf::Event::Closed:

                                        Window.close();
                                        break;

                        }

                }

                Window.clear(sf::Color::White);

                sf::Transform B(std::cos(30.0f), 0.0f, std::sin(30.0f), 0.0f, 1.0f, 0.0f, -std::sin(30.0f), 0.0f, std::cos(30.0f));
                Window.draw(Sprite, B);

                Window.display();

        }

}

What do you actually mean by "transformation origin"?
« Last Edit: September 09, 2012, 04:53:49 pm by HemoGoblin »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: xy rotation using transform?
« Reply #3 on: September 09, 2012, 04:29:15 pm »
Btw there's a code=cpp tag for highlighting sourcecode instead of using the quote tag (dropdown box right)... ;)

So you're infact using sf::Sprite, but why can't you just call sprite.rotate()?
What do you imagine under the term xy rotation?

Do you want to rotate the sprite around one edge?

Also take a look at the example in the documentation for sf::Transform, you don't need to specify all the parameters. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

HemoGoblin

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: xy rotation using transform?
« Reply #4 on: September 09, 2012, 04:37:10 pm »
Sprite.rotate uses z-rotation only, i need to rotate it also around the other axes (to achieve simple "3d" effect).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: xy rotation using transform?
« Reply #5 on: September 09, 2012, 05:03:07 pm »
Sprite.rotate uses z-rotation only, i need to rotate it also around the other axes (to achieve simple "3d" effect).
Ah now I understand! :)

Will that even work properly? I mean the resulting geometry won't be a rectangle anymore, thus you'll either have to directly change the texture/image to get that effect, or use something else instead of sf::Sprite (e.g. sf::VertexArray or sf::ConvexShape)...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: xy rotation using transform?
« Reply #6 on: September 09, 2012, 05:07:19 pm »
You can't work in other planes with sfml-graphics, it's a 2D module. The 3x3 matrix encapsulated by sf::Transform will only let you rotate around the Z axis. The last column of the matrix is not a Z column, it's the "W" column, which allows to handle translations.

If you want to do 3D stuff you're on your own.
Laurent Gomila - SFML developer

HemoGoblin

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: xy rotation using transform?
« Reply #7 on: September 09, 2012, 05:09:09 pm »
Okay, thanks.

 

anything