SFML community forums

Help => Graphics => Topic started by: kkray on January 02, 2011, 06:09:12 pm

Title: Chain of transformation, how to?
Post by: kkray 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?
Title: Chain of transformation, how to?
Post by: Laurent 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.
Title: Chain of transformation, how to?
Post by: kkray 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.
Title: Chain of transformation, how to?
Post by: kkray 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 :(
Title: Chain of transformation, how to?
Post by: Groogy 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.
Title: Chain of transformation, how to?
Post by: kkray 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.
Title: Chain of transformation, how to?
Post by: Groogy 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?
Title: Chain of transformation, how to?
Post by: kkray 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".
Title: Chain of transformation, how to?
Post by: Groogy on January 02, 2011, 08:42:08 pm
It should: http://www.sfml-dev.org/documentation/2.0/classsf_1_1Drawable.htm#af14b17e4f5a73d2b1457707734643550
Title: Chain of transformation, how to?
Post by: Laurent 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.
Title: Chain of transformation, how to?
Post by: kkray 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 :)
Title: Chain of transformation, how to?
Post by: Laurent on January 02, 2011, 10:06:37 pm
Sorry, I don't understand what you want. Can you explain "get rectangle from texture"?
Title: Chain of transformation, how to?
Post by: kkray on January 02, 2011, 10:36:00 pm
(http://img593.imageshack.us/img593/1373/aaaaaaaaaaaaa.png)
Title: Chain of transformation, how to?
Post by: Laurent 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.
Title: Chain of transformation, how to?
Post by: kkray 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 ?
Title: Chain of transformation, how to?
Post by: Laurent on January 02, 2011, 11:13:25 pm
Quote
Should I expect some troubles between my SpriteExt and base SFMP-API ?

Yes: you can't write it :lol:

If you do it 100% with OpenGL, you won't be able to use the sfml-graphics internal stuff (render windows, views, shaders, etc.) It won't be integrated at all like SFML drawables.

If you want to integrate it to SFML you have to inherit from sf::Drawable, but this class already implements what you want to get rid of.
Title: Chain of transformation, how to?
Post by: kkray on January 02, 2011, 11:24:49 pm
Hm.... I was going to inherit my class from sf::Drawable :)
In any case, I am going to try :)
Title: Chain of transformation, how to?
Post by: Laurent on January 02, 2011, 11:31:48 pm
Quote
Hm.... I was going to inherit my class from sf::Drawable

Doesn't make sense. You'll get all the transformation setters/getters that you want to avoid, and it will be applied automatically, you can't replace it with your own transform system.
Title: Chain of transformation, how to?
Post by: kkray on January 02, 2011, 11:38:06 pm
Oh noooo... :'(
What should I do?
I realy, realy need chain of transformations for sprites.
Title: Chain of transformation, how to?
Post by: kkray on January 02, 2011, 11:40:16 pm
I want sf::Sprite::SetMatrix :D
Title: Chain of transformation, how to?
Post by: Laurent on January 03, 2011, 08:44:00 am
Quote
I realy, realy need chain of transformations for sprites.

If you wait a little bit, it should be available soon in SFML 2.
Title: Chain of transformation, how to?
Post by: kkray on January 03, 2011, 05:01:52 pm
Oh, it's great! How soon? :)
Title: Chain of transformation, how to?
Post by: Laurent on January 03, 2011, 07:05:46 pm
Don't know... maybe never 8)