PDA

View Full Version : [D3D] 2D transformations



chronozphere
06-04-2006, 06:44 PM
Hi 8)

I have a question concerning 2D transformations.

I think its clever to use the screen-coordinates for 2d drawing, (I mean adding "D3DFVF_XYZRHW" to your vertex-description)
because you can easily draw a vertex-quad to the exact screen-position you want. :)

The only problem is that when i want to move a primitive, i am forced to lock/unlock the vertexbuffer and change the coordinates for each vertex. This sounds like a very slow method. :(

I've read an article on MSDN wich tells me that when i use these screen-coordinate-vertices,
They will be directly send to the hardware-rasterizer.
So i must do all the transformations myself.

So what is the best way to transform a primitive using screen-coordinates??
Is Locking/Unlocking the only way or are there better and faster methods available??

Thanx in advance. :D

Clootie
06-04-2006, 09:29 PM
You can use orthogonal projection matrix - it allows to use simple and intuitive translation matrixes. Look for D3DXMatrixOrthoLH for additional information.

Anyway if you have, for example, 100 UI boxes (or sprites) and want to render them on screen -- it will be MUCH faster to lock vertex buffer, fill coordinates for ALL these boxes and render them using single DrawIndexedPrimitive call (Yes, this way you will need to calculate new positions by yourself).

chronozphere
07-04-2006, 05:48 PM
Thanx.. :D i've now implented orthographic projection and it seems to work OK. :)

I've also found two good artilces :o :D :

http://www.gamedev.net/reference/programming/features/2d3dquads/page5.asp
http://www.gamedev.net/reference/articles/article1434.asp

Now I have some other questions:

The thing you mentioned about -drawing 100 objects in a single vertexbuffer- , is covered in the first article and is called "Batching".
I want to use it because it would give me some extra speed. :razz:

But then i must write some sort of system that manages objects (mostly quads) within a vertexbuffer. Each object must have a few vertice-indexes and his own texture-coords, colors and transformations.
I think this is possible but i dont know how to do it.


First of all, i must know how to change the ammount of vertices inside a vertexbuffer after creating it. Is this possible, if Yes... How do i do that??

And when i draw the contents of a vertexbuffer, many vertices and polygons will lie outside the screen. I wonder what will happen, are those vertices ignored, or will they slow down the game (If they do, how to avoid it)??

So. Can anyone give me some advice?? :?

Clootie
07-04-2006, 08:33 PM
VertexBuffer size is fixed. But you are not forced to draw all it's content at single DIP call. You can freely choose that continous number of vertices to draw. I.e. you can draw 7 triangles with coordinates starting from 8 vertex and continuing to 8+7*3 = 29'th vertex. Or, if you use DrawIndexedPrimitive, then it's up to you that vertices to choose from (as you explicictly say that you draw triangles from, for example, 1,6,7 and 9,2,0 vertices in VBuffer).

So, you can fill exact vertices in VB and draw triangles using only these vertices. And on next frame write to VB other vertices and draw again.

alexione
10-04-2006, 07:12 PM
One more question (hope Clootie would answer it:)

Since we anyway fill info about vertices/indices in system memory (if it's managed it will automaticly be transleted to gfx-card when necessary), couldn't we use Draw(Indexed)PrimitiveUP with SAME performances in case of 2D coordinates?

alexione
10-04-2006, 07:14 PM
One more question (hope Clootie would answer it:)

Since we anyway fill info about vertices/indices in system memory (if it's managed it will automaticly be transleted to gfx-card when necessary), couldn't we use Draw(Indexed)PrimitiveUP with SAME performances in case of 2D?

Clootie
10-04-2006, 09:09 PM
Sure you could, but it's actually is not recommended by IHVs. If you are trying to make a quick hack just to draw couple of poligons - this probably will be fine, but if you going to draw something around 100 triangles - it will be way better to use DIP with vertex buffer.

Problem here is that Direct3D runtime actually can use two methods of passing data from DIPUP call and in both cases it adds some perfomance hits.

chronozphere
11-04-2006, 12:50 PM
Thanx clootie for all your answers. :)

As I said, orthographic projection works fine now.
I am now only using a few objects. If any preformance problems occurd concerning Transformations, i will post them in this thread.

Clootie
11-04-2006, 08:19 PM
good luck :D