Projection matrices

Xcrypt 101 Sep 12, 2011 at 14:00

I’ve been wondering if I had to post this in the graphics or math section, since it is closely related to DirectX. So If I chose wrong, please move this thread.

XMMATRIX matScale = XMMatrixScaling(10.0f,10.0f,1.0f);
XMMATRIX matTranslate = XMMatrixTranslation(10.0f,10.0f,0.0f);
XMMATRIX matWorld = XMMatrixMultiply(matScale,matTranslate);

XMMATRIX matProj = XMMatrixOrthographicOffCenterLH( 0.0f, 300.0f, 0.0f, 225.0f, 0.1f, 100.0f );
XMMATRIX matMvp = XMMatrixMultiply(matWorld, matProj);
matMvp = XMMatrixTranspose(matMvp);

With this code I’ve learned to change the offset and scale of the axis. This moves the origin to the bottom-left corner of my rendertarget. However, if I wanted the origin to be at the top-left corner of my rendertarget(and also inverse the Y coordinates), what would I have to do?

2 Replies

Please log in or register to post a reply.

rouncer 103 Sep 12, 2011 at 14:16

you could always go pos.y=-pos.y in the shader, that would flip it then, but that only helps if your using shaders, you can actually modify that orthographic matrix to do it, maybe itll involve the view matrix too… trial and error?

Xcrypt 101 Sep 12, 2011 at 15:07

pos.y = -pos.y in the shader wouldn’t be correct. It would flip everything indeed, but that’s not really what I meant to ask. Right now if I Set that translation matrix to (0.0f,0.0f,0.0f) (and the vertices are centered as well) the surface would show up centered, at the bottom-left corner of the rendertarget. I want it to show up centered, at the top-left corner of the rendertarget. the Y value of the translationmatrix should be 0 for the top-left corner, and the height of the rendertarget for the bottom-left corner.

I have tried trial and error. I couldn’t immediately find anything… That’s why I am asking here.