Jump to content
  • Advertisement
Sign in to follow this  
Constantin

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!