How to translate (x/y) an orthogonal projection

Started by
1 comment, last by ET3D 15 years, 8 months ago
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);
Advertisement
For reasons I don't understand, using _41 and _42
instead of _31 and _32 does the trick.
Translation is normally in the fourth row. I don't know why the original code puts it in the third.

This topic is closed to new replies.

Advertisement