Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture Mapping Matrix.

Started by ChrisLamothe1970 Apr 25, 2007 at 4:00 PM 3 replies 950+ views
Original Post
ChrisLamothe1970
ChrisLamothe1970
Hi, I have a texture that appears in the top right hand quad of my screen. This is correct given the vertex buffer I am using. Basically I need the correct matrix conversion that will take those vertices and map them into my screen with the top left hand corner of the screen being (0,0) and the bottom right hand corner being (800,800). I realise that all I need to do is subtract 1.0 from the 2/width and 2/height setting that multiplies the X and Y of a vertex. I use this call: D3DXMatrixOrthoLH(&matOrtho, 800.0f, 800.0f, 0.1f, 10.0f) which essentially gives me an origin at the middle of the screen (and not the top left hand corner - which in texture space is (-1,1). I tried augmenting this matrix with : matOrtho._12 = -1.0f; matOrtho._21 = -1.0f; to get the -1 subtraction which I need. This doesn't work. Any ideas how I can get my mapping? Cheers, Chris Code: --------------------------------------------------------------------- Vertex buffer: #define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_TEX1 ) Vertex g_quadVertices[] = { { 0.0f, 0.0f, 5.0f, 0.0f, 0.0f }, // TLHCorner { 800.0f, 0.0f, 5.0f, 1.0f, 0.0f }, // TRHCorner { 0.0f, 800.0f, 5.0f, 0.0f, 1.0f }, // BLHCorner { 800.0f, 800.0f, 5.0f, 1.0f, 1.0f } // BRHCorner }; --------------------------------------------------------------------- Camera projections: D3DXMATRIX matOrtho; D3DXMATRIX matIdentity; D3DXMatrixOrthoLH(&matOrtho, 800.0f, 800.0f, 0.1f, 10.0f); D3DXMatrixIdentity (&matIdentity); g_pd3dDevice->SetTransform (D3DTS_PROJECTION, &matOrtho); g_pd3dDevice->SetTransform (D3DTS_WORLD, &matIdentity); g_pd3dDevice->SetTransform (D3DTS_VIEW, &matIdentity); g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
sirob
sirob
D3DXMatrixOrthoOffCenterLH ?
Sirob Yes.» - status: Work-O-Rama.
ChrisLamothe1970
ChrisLamothe1970
Hello,

Thanks for the response.

I looked at D3DXMatrixOrthoOffCenterLH before but I'll revisit if you feel it might be the way forward...

Cheers,
Chris
ChrisLamothe1970
ChrisLamothe1970

No, D3DXMatrixOrthoOffCenterLH won't work because anything multiplied by zero is zero!

I need a POST matrix subtraction of 1.0 from each of my vertices in my vertexbuffer to give me the coordinate system I want.

I use D3DXMatrixOrthoLH(&matOrtho, 800.0f, 800.0f, 0.1f, 10.0f). This gives a multiplier of 2.0f/800.0f which when applied to my vertices (see my first post) will position the texture's bottom left and corner in the middle of the screen at (0,0).

I want the texture to effectively have it's origin at (0,0) in Screen Coordinates (i.e., the top left hand corner of my window).

So, regardless of whether I use D3DXMatrixOrthoLH or D3DXMatrixOrthoOffCenterLH it won't work as it is.

How do I get the correct mapping?

Any offers?!

Cheers,
Chris
ChrisLamothe1970
ChrisLamothe1970
Problem solved.

My apologies, it was trivial.

D3DXMatrixTranslation(&matTrans, -1.0f, -1.0f, 0.0f);
matOrtho *= matTrans;

Thanks
Chris

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.