Archived

This topic is now archived and is closed to further replies.

Fyyar

Setting a viewport..?

Recommended Posts

Hello all! I have a simple question with a simple (I hope) answer. If I use the following code.. ("borrowed" and modified from another post)
  
D3DXMATRIX mat;	
//Projection Matrix	

D3DXMatrixOrthoLH(&mat,	1.0f, 1.0f, 0.0f, 1.0f);
m_pDevice->SetTransform(D3DTS_PROJECTION, &mat);

//World Matrix	

D3DXMatrixIdentity(&mat);	
m_pDevice->SetTransform(D3DTS_WORLD, &mat);	

//View Matrix	

D3DXMatrixLookAtLH(&mat, &D3DXVECTOR3(0.0f, 0.0f, -0.5f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
m_pDevice->SetTransform(D3DTS_VIEW, &mat);
  
.. I get a situation where the upper left corner has coords. (-0.5,0.5) and the lower right corner has (0.5,-0.5). However, I want the upper left corner to have coords. (0.0,0.0) and the lower right (1.0,1.0). How do I do this?

Share this post


Link to post
Share on other sites
The first vector of LookAtLH is your camera position.
The second is the point you are looking at.

By moving both these vectors (points really) 0.5 along
the x-axis and 0.5 down the y-axis (negative), your
resulting screen coordinates should meet your requirement.

thus:

D3DXMatrixLookAtLH(&mat, &D3DXVECTOR3(0.0f, 0.0f, -0.5f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));

should be:

D3DXMatrixLookAtLH(&mat, &D3DXVECTOR3(0.5f, -0.5f, -0.5f), &D3DXVECTOR3(0.5f, -0.5f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));

Left-handed and right-handed orientation sometimes throws me
off though, so if you end up in the wrong quadrant (like
Voyager), just change the sign of the x or the y or both :-)

Share this post


Link to post
Share on other sites