home | login | register | DMCA | contacts | help | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я


my bookshelf | genres | recommend | rating of books | rating of authors | reviews | new | форум | collections | читалки | авторам | add
fantasy
space fantasy
fantasy is horrors
heroic
prose
  military
  child
  russian
detective
  action
  child
  ironical
  historical
  political
western
adventure
adventure (child)
child's stories
love
religion
antique
Scientific literature
biography
business
home pets
animals
art
history
computers
linguistics
mathematics
religion
home_garden
sport
technique
publicism
philosophy
chemistry
close

Loading...


2D Camera

To setup the camera for 2D objects we need to change the projection matrix from a perspective one used in 3D to an orthogonal projection. When using a perspective projection, objects that are further away from the camera are smaller than objects that are closer to the camera. When using an orthogonal projection, an object will be the same size no matter how far it is from the camera. For example, when you use your 3D modelling program, you normally get three orthogonal projections (top, side and front) and a perspective projection (3D). The code for setting the camera for 2D is shown below:

void CGame::Setup2DCamera() {

 D3DXMATRIX matOrtho;

 D3DXMATRIX matIdentity;

 //Setup the orthogonal projection matrix and the default world/view matrix

 D3DXMatrixOrthoLH(&matOrtho, (float)m_nScreenWidth, (float)m_nScreenHeight, 0.0f, 1.0f);

 D3DXMatrixIdentity(&matIdentity);

 m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matOrtho);

 m_pD3DDevice->SetTransform(D3DTS_WORLD, &matIdentity);

 m_pD3DDevice->SetTransform(D3DTS_VIEW, &matIdentity);

 //Make sure that the z-buffer and lighting are disabled

 m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);

 m_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

}

In addition to changing the projection matrix, we also set the world and view matrices to an identity matrix and disable the z-buffer and lighting. We disable the z-buffer so that everything that is rendered from then on will appear on top of objects that have already been rendered (3D objects).


Steps for 2D in 3D Rendering | DirectX 8 Programming Tutorial | 2D Objects







Loading...