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

Author Topic: Chain of transformation, how to?  (Read 7893 times)

0 Members and 2 Guests are viewing this topic.

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« on: January 02, 2011, 06:09:12 pm »
Hello everybody.

In my project I need to apply chain of transformation for object.
For example I need, in order:
1. scale
2. rotate
3. move
4. scale (AGAIN!)
5. rotate
6. move
...
n. scale
n+1. rotate
n+2. move
n+3. draw to the screen

I need this, becuse I have an hierarchy of objects, like a tree. And if parent moves, then all of childs must move too. The same for scaling, rotating and so on.

I found sf::Matrix3 class, which can be built from transformations and can be multiplied with other matrixes, but I don't understand how to apply my result matrix to the sprite.

Can you help me? What the best way to do it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Chain of transformation, how to?
« Reply #1 on: January 02, 2011, 07:05:51 pm »
You can't, SFML is not made to allow this.

However, if you draw drawables inside other drawables (ie. in the Render function of your own class derived from sf::Drawable), the transformations are combined. You can use this to build a hierarchy of drawables.
Laurent Gomila - SFML developer

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #2 on: January 02, 2011, 07:21:06 pm »
Oh.. I'm sorry to hear it.
Also, I cant find a way to draw a quad from texture to quad on screen. It's impossible too? :(

PopCapFramework has a best draw-function I've ever seen -- DrawImageTransform( TransfromMatrix ) where TransfromMatrix can be produced from other matrixes, and matrix-class has functions like "translate","scale","rotate". Do you plan to implement functions like this?

Or, maybe, just Quad-class with tex-coords, scr-coords, texture, z-buffer for vertices, colors and so on? So that we coold fill vertext data by mulitplication point-vectors on matrix.

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #3 on: January 02, 2011, 07:36:34 pm »
By the way, first time when I saw Sprote::Move, Rotate and Scale methods I thought that code like this:
Code: [Select]
spr.Scale( sx1,sy1 );
spr.Rotate( ang1 );
spr.Scale( sx2,sy2 );

means something like this:
Scale sprite, THEN rotate it and THEN scale it again. This would be wonderful :(

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Chain of transformation, how to?
« Reply #4 on: January 02, 2011, 07:41:10 pm »
Sprite's don't affect the original image, they are just a set of values that will be used when it's protected sf::Drawable::Render method is called. So they don't do anything until the sprite is actually being drawn.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #5 on: January 02, 2011, 07:44:54 pm »
Quote from: "Groogy"
Sprite's don't affect the original image, they are just a set of values that will be used when it's protected sf::Drawable::Render method is called. So they don't do anything until the sprite is actually being drawn.

Yes, I know. So what? I dont understand you.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Chain of transformation, how to?
« Reply #6 on: January 02, 2011, 07:54:51 pm »
what you want are the modelview matrix transformation, but no opengl call is made until the sprite is drawn.

*EDIT*
Though now when I look at your post again... The sprite should scale by the amount that you write, rotate it by that amount of degrees, and then scale it by a new amount... You  mean that it doesn't?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #7 on: January 02, 2011, 08:06:02 pm »
Try to call scale, rotate and scale again. Only one scale works. Order of command also doesnt matter :(

spr.Rotate and then spr.Scale are not equal to "rotate and THEN scale".

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Chain of transformation, how to?
« Reply #9 on: January 02, 2011, 08:44:10 pm »
Quote
Also, I cant find a way to draw a quad from texture to quad on screen. It's impossible too?

Can't you do this with a sprite?

Quote
PopCapFramework has a best draw-function I've ever seen -- DrawImageTransform( TransfromMatrix ) where TransfromMatrix can be produced from other matrixes, and matrix-class has functions like "translate","scale","rotate". Do you plan to implement functions like this?

I don't know. Pure matrices are of course more flexible, but it is very convenient to have this "position/rotation/scale/center" API with everything separated and combined at render time. Anyway, this is something that I have to think about for SFML 2.

Quote
Or, maybe, just Quad-class with tex-coords, scr-coords, texture, z-buffer for vertices, colors and so on? So that we coold fill vertext data by mulitplication point-vectors on matrix.

Technically you'll be able to do this in SFML 2. But this is very inefficient, it's almost free to let the GPU transform the vertices with a matrix.

Quote
Though now when I look at your post again... The sprite should scale by the amount that you write, rotate it by that amount of degrees, and then scale it by a new amount... You mean that it doesn't?

No it doesn't. All transform parameters are independant. If they were not, I wouldn't be able to provide the corresponding getters. So calling Scale multiple times will combine the factors together, but it won't be impacted by the current position/rotation/center.
Laurent Gomila - SFML developer

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #10 on: January 02, 2011, 08:55:57 pm »
Quote from: "Laurent"
Quote
Also, I cant find a way to draw a quad from texture to quad on screen. It's impossible too?

Can't you do this with a sprite?


I cant, because I want to get rectangle from texture, and draw a quad(!), not rectangle.

(0,0),(w,0),(w,h),(0,h) --> (1,2),(3,4),(5,6),(7,8) for example. I want to get a way to render rects from texture to ANY quad on screen. This feature + vectors + matrixes = PROFIT! :)

And I dont want to write my own render-method, OGL is not my love :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Chain of transformation, how to?
« Reply #11 on: January 02, 2011, 10:06:37 pm »
Sorry, I don't understand what you want. Can you explain "get rectangle from texture"?
Laurent Gomila - SFML developer

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #12 on: January 02, 2011, 10:36:00 pm »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Chain of transformation, how to?
« Reply #13 on: January 02, 2011, 10:39:19 pm »
Ok I get it. With SFML you'll only be able to draw it with a sprite, and apply the transformations that are provided by its API. You can't use custom geometry/transformation, unless you go with OpenGL directly.
Laurent Gomila - SFML developer

kkray

  • Newbie
  • *
  • Posts: 12
    • View Profile
Chain of transformation, how to?
« Reply #14 on: January 02, 2011, 10:59:32 pm »
Ok, thanks for answer :)
I'm going to write SpriteExt class with modified Move, Rotate, etc. methods, which will accumulate transformation, and in virtual draw method will use them as a chain. Most likely I will not write methods like GetPosition, becouse it will be hard work, and I dont need these methods for my task.

Should I expect some troubles between my SpriteExt and base SFMP-API ?