DirectX viewports

Started by
23 comments, last by Evil Steve 16 years, 1 month ago
Quote:Original post by Sync Views
I suppose I'll cover them in the next two years then....not sure I really want to wait that long though so can you explain what I basicly need to do? eg looking at that matrix function I'm realy not seeing what I'm meant to change to do rotation as well :( (I'm asuming it's not as simple as how many degress/radians as it would need to take into acount where the "centre" of my object is?)
Again, googling for matrices should give loads of results.

If you have a matrix that translates an object by (10, 20), and a matrix that rotates an object by 45 degrees (Rotations are always about the origin), you can combine them into a matrix that will either rotate by 45 degrees, then translate by (10, 20), or you can combine them into a matrix that translates first, then rotates, depending on the order you multiply them in.

It's a bit difficult to go over it in detail, but you can think of it as m1 * m2 means "First do m1, then do m2", so:
D3DXMATRIX matRotate, matTranslate, matFinal;// Create a matrix that rotates by 45 degrees about the Z axis:D3DXMatrixRotationZ(&matRotate, D3DXToRadian(45.0f));// Create a matrix that translates by (10, 20, 0):D3DXMatrixTranslation(&matTranslate, 10.0f, 20.0f, 0.0f);// Multiply the two matrices to give one that rotates, then translates:D3DXMatrixMultiply(&matFinal, &matRotate, &matTranslate);// matFinal is now a matrix that rotates things by 45 degrees, then translates// them by (10, 20, 0).



EDIT:
If you have a tile or set of tiles which are from (0, 0) to (4000, 4000), and you want to rotate about the middle of them (2000, 2000), you need to:
Translate by (-2000, -2000)
Rotate
Translate by (2000, 2000)
Advertisement
so roating is always aeround the origin of the world as in "0,0,0" not just the centre point between the vertices?

So to rotate an image around the point I want I need to:
-Translate so my origin point is at 0,0,0
-Rotate
-Translate it back to where I want it
Quote:Original post by Sync Views
so roating is always aeround the origin of the world as in "0,0,0" not just the centre point between the vertices?

So to rotate an image around the point I want I need to:
-Translate so my origin point is at 0,0,0
-Rotate
-Translate it back to where I want it
Yup, exactly. The rotation is done per vertex, and a vertex is just a point in space, so the GPU doesn't know where to rotate it "relative" to, so it has to use the origin.
ok got that all working nicely now with zooming, roation and translation :)

1 last thing though. If I wanted to do a split screen type thing how do I make it so d3d transforms and draw it to just one area of the screen not the entire screen? (eg just the left half of the screen) so I can have 2 "views" one for each of the two players?
Quote:Original post by Sync Views
ok got that all working nicely now with zooming, roation and translation :)

1 last thing though. If I wanted to do a split screen type thing how do I make it so d3d transforms and draw it to just one area of the screen not the entire screen? (eg just the left half of the screen) so I can have 2 "views" one for each of the two players?
That's when you use multiple viewports. You'd call SetViewport() to set a viewport that covers the left side of the screen, render, then call SetViewport() to set the right side of the screen as the viewport, then render again.

Someone here may be able to suggest an alternative method too.

This topic is closed to new replies.

Advertisement