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

Author Topic: [SOLVED] Transformation matrices and sprites  (Read 4993 times)

0 Members and 1 Guest are viewing this topic.

lazerblade

  • Newbie
  • *
  • Posts: 14
    • View Profile
[SOLVED] Transformation matrices and sprites
« on: April 07, 2013, 04:59:38 am »
I've got a set of transformations that need applied to a sprite in a certain order, each of them effecting the next. The obvious thing to do is to just use sf::Transform and apply it to a sprite, but scanning the manual(and eclipse auto suggest) doesn't turn anything up. My first thought was "Okay, fine. We'll trick it. We'll use myTransform.transformRect(rectangleOfMySprite) to steal the data we need and apply it to the sprite," but transformRect() only returns the bounding box of the transformed rectangle.

Scanning the forums, I see that a couple of years ago another user wanted something very similar-basically sf::Sprite::setTransform(): http://en.sfml-dev.org/forums/index.php?topic=3878.15

At the time, such a thing was apparently infeasible, but I still don't see anything dealing with this in SFML2. So I guess my question is: in SFML 2 how can I apply sequential dependent transforms to a sprite, and how big of a headache would it be to make it happen if it's not a built-in feature?
« Last Edit: April 07, 2013, 06:27:21 am by lazerblade »

FRex

  • Hero Member
  • *****
  • Posts: 1846
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Transformation matrices and sprites
« Reply #1 on: April 07, 2013, 05:15:25 am »
I don't understand the questions clearly enough. Do you want to apply sf::Transform to a sprite? Then check out render states: http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderStates.php
And if you have few 3x3 matrices then you can build sf::Transforms from them and multiply these in right order and then pass in render states.
« Last Edit: April 07, 2013, 05:17:05 am by FRex »
Back to C++ gamedev with SFML in May 2023

lazerblade

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Transformation matrices and sprites
« Reply #2 on: April 07, 2013, 06:27:03 am »
First one, applying an sf::Transform to a sprite. You hit the nail on the head. I feel the combination of gratification at solving a difficult problem and shame for saying "Renderstates? Don't look important to me," when I first read about them when learning SFML.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED] Transformation matrices and sprites
« Reply #3 on: April 07, 2013, 03:36:54 pm »
Generally, sf::Transform transforms single points, not whole graphical objects. What is done in the case of sf::Sprite, is that its 4 corner vertices are taken and individually transformed, leading to a new rectangle.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [SOLVED] Transformation matrices and sprites
« Reply #4 on: April 07, 2013, 05:08:27 pm »
Quote
Generally, sf::Transform transforms single points, not whole graphical objects. What is done in the case of sf::Sprite, is that its 4 corner vertices are taken and individually transformed, leading to a new rectangle.
sf::Transform can transform whole graphical objects, if it is given to the draw function via sf::RenderStates. I'd even say that it's its most important role. sf::Sprite is not a special case, it works the same for entity that you can pass to the draw function (the transform is directly forwarded to OpenGL as the model-view matrix).
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED] Transformation matrices and sprites
« Reply #5 on: April 07, 2013, 05:22:29 pm »
You are right, I should have formulated that better. The sf::Transform API on its own isn't able to transform graphical objects, in the sense of transform.apply(sprite). So you cannot use sf::Transform to alter the position, rotation or scale of an sf::Transformable, therefore people cannot implement physics or game logics like this -- not that they should, but the idea might come up.

The transform is applied in combination with sf::RenderStates during drawing, and implemented by transforming each vertex.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

lazerblade

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: [SOLVED] Transformation matrices and sprites
« Reply #6 on: April 07, 2013, 08:13:07 pm »
I understand this. I'm just passing a transform renderstate to the draw function along the with spite. I needed this to help me draw the various moving limbs of an enemy.

 

anything