# How to translate (x/y) an orthogonal projection

This topic is 3793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I used the sample from http://www.mvps.org/directx/articles/tilerender/ to render a large scene. It works perfectly if I use a perspective projection. If I use D3DXMatrixOrthoLH, it works only for a single tile. The reason for this has to be how the projection is offset for each tile. The code is reproduced below. Thanks for any help anyone can provide. // get the current projection matrix and save a copy D3DXMATRIX oldProj,newProj; pDev->GetTransform(D3DTS_PROJECTION,&oldProj); newProj=oldProj; // scale the projection matrix on x and y axis newProj._11*=numTiles; newProj._22*=numTiles; // loop through the tiles in X for (int i=0;i<numTiles;i++) { // offset x coordinates newProj._31=(numTiles-1)-i*2.0f; // loop through the tiles in Y for (int j=0;j<numTiles;j++) { // offset y coordinates newProj._32=-((numTiles-1)-j*2.0f); // set the modified projection matrix pDev->SetTransform(D3DTS_PROJECTION,&newProj); // call the rendering function if (FAILED(hr=renderFunc())) { surf->Release(); return hr; } // get the back buffer pointer if(FAILED(hr=pDev->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&backbuf))) { surf->Release(); return hr; } // copy the tile to the image buffer and release the back buffer RECT destRect; destRect.left=desc.Width*i; destRect.right=destRect.left+desc.Width; destRect.top=desc.Height*j; destRect.bottom=destRect.top+desc.Height; hr=D3DXLoadSurfaceFromSurface(surf,NULL,&destRect, backbuf,NULL,NULL,D3DX_FILTER_NONE,0); backbuf->Release(); if (FAILED(hr)) { surf->Release(); return hr; } // show current tile pDev->Present(0,0,0,0); } } // restore projection matrix pDev->SetTransform(D3DTS_PROJECTION,&oldProj);

##### Share on other sites
For reasons I don't understand, using _41 and _42
instead of _31 and _32 does the trick.

##### Share on other sites
Translation is normally in the fourth row. I don't know why the original code puts it in the third.

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×