2D UI Transformations
I was wondering, what would be the best way to resize a quad?
- Each time it changes, crack open the vertex buffer and readjust the size of the quad.
- Or, Transform the object to (0,0), Scale it, and Transform it back to where it's supposed to sit?
Am I guaranteed that, when I scale, it won't scale it' translation?
Quote:what would be the best way to resize a quad?
If you're going to do the resizing often, leave the buffer along and apply a scaling transform. If you properly order the translate-scale-translate the scale won't affect the translation.
You can, also, just create the quad at (0,0) to begin with and use scale-translate all the time.
Quote:Or, Transform the object to (0,0), Scale it, and Transform it back to where it's supposed to sit?
I assume you meant translate, not transform (transformation can be anything, including translation). In that case: Yes, thats the way you do it, if you intend to scale your quad "locally".
Quote:Each time it changes, crack open the vertex buffer and readjust the size of the quad.
Don't know what you mean by "crack open" exactly. Do you intend to read back from a vertex buffer? Can you show us some example code ?
Quote:Original post by Buckeye
If you're going to do the resizing often, leave the buffer along and apply a scaling transform. If you properly order the translate-scale-translate the scale won't affect the translation.
You can, also, just create the quad at (0,0) to begin with and use scale-translate all the time.
Great, this is the answer I was looking for.
Hello,
I found out, that for me (in my D3D9 based engine) it best works to use one dynamic vertex buffer for all ingame GUIs and fill it every frame with GUI quads. That way I have total control over the quads. I can update the quads every frame and animate their position, color/alpha and texture coordinates very easily. Vertex updates are really fast if you use a dynamic vertex buffer along with D3DLOCK_DISCARD or D3DLOCK_NOOVERWRITE. In my case there was almost no performance difference between the two approaches:
- update GUI quads every frame using dynamic VB.
versus
- cache GUI quads in a static VB once, draw them many times
So I would naturally opt for the first way - fill the VB every frame.
To your second question: scaling operation works relative to the origin of the coordinate system (in fact every transformation works relative to the origin). Say, your quad has screen coordinates (left,top,right,bottom) = (2,4,8,6), then scaling them by uniform scale coeficient 3.0 will result in new coordinates (6,12,24,18). So yes, the quad would seem to be translated too. What you want to do, is to translate the quad by the negative value of its absolute center position before scaling, then scale and then translate by the same value back. Of course you can combine these 3 operations into a single transformation matrix and perform the operation in one step.
Hope that helped a little.
I found out, that for me (in my D3D9 based engine) it best works to use one dynamic vertex buffer for all ingame GUIs and fill it every frame with GUI quads. That way I have total control over the quads. I can update the quads every frame and animate their position, color/alpha and texture coordinates very easily. Vertex updates are really fast if you use a dynamic vertex buffer along with D3DLOCK_DISCARD or D3DLOCK_NOOVERWRITE. In my case there was almost no performance difference between the two approaches:
- update GUI quads every frame using dynamic VB.
versus
- cache GUI quads in a static VB once, draw them many times
So I would naturally opt for the first way - fill the VB every frame.
To your second question: scaling operation works relative to the origin of the coordinate system (in fact every transformation works relative to the origin). Say, your quad has screen coordinates (left,top,right,bottom) = (2,4,8,6), then scaling them by uniform scale coeficient 3.0 will result in new coordinates (6,12,24,18). So yes, the quad would seem to be translated too. What you want to do, is to translate the quad by the negative value of its absolute center position before scaling, then scale and then translate by the same value back. Of course you can combine these 3 operations into a single transformation matrix and perform the operation in one step.
Hope that helped a little.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement