In MFC SDI,How to write D3D code
In MFC SDI,How to write D3D code?
I had wroteen some code about D3D in MFC SDI project.
But I have a problem that when I resisze the view, the model will resize.
I had reccomputed the projective matrix by the view size (when I resize the View).
I want to keep the model's size when I resize the View.
[Edited by - akira32 on August 24, 2007 6:49:19 AM]
Quote:Original post by Kiryn
Well the model is suppose to resize due to the resizing of the window.
I had tried to modify the projective matrix and viewport.
But it seems to be error.
HRESULT hr;
hr=m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 1.0f, 0);
m_ViewClientSize.cx=cx;
m_ViewClientSize.cy=cy;
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)m_ViewClientSize.cx / (float)m_ViewClientSize.cy,
1.0f,
1000.0f);
if (m_pD3DDevice)
m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &proj);
D3DVIEWPORT9 ViewPort;
m_pD3DDevice->GetViewport(&ViewPort);
ViewPort.Width=m_ViewClientSize.cx;
ViewPort.Height=m_ViewClientSize.cy;
if (m_pD3DDevice)
m_pD3DDevice->SetViewport(&ViewPort);
On resizing you also need to Reset the D3D device. Otherwise DirectX will stretch the content with the original buffer size.
Basically you need to release all non-managed-pool resources, call Reset on the IDirect3dDevice (with the modified PresentationParameters) and rebuild your non-managed resources (if you have any).
The modified presentation parameters are the same as on the initialising but have the new size for the backbuffer.
You can use exactly the same code you'd need for Alt-Tabbing in fullscreen mode (which results in a lost device).
The modified presentation parameters are the same as on the initialising but have the new size for the backbuffer.
You can use exactly the same code you'd need for Alt-Tabbing in fullscreen mode (which results in a lost device).
Check the second argument of D3DXMatrixPerspectiveFovLH(...).
The Fov value is also important to decide the size of model.
In my case, I set the projection matrix like this.
float Fov = atanf( (uCY*0.5f)/300 );
D3DXMATRIX matProj;
float fAspect = static_cast<float>(uCX)/uCY;
D3DXMatrixPerspectiveFovLH( &matProj, Fov, fAspect, 0.1f, 100.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
The Fov value is also important to decide the size of model.
In my case, I set the projection matrix like this.
float Fov = atanf( (uCY*0.5f)/300 );
D3DXMATRIX matProj;
float fAspect = static_cast<float>(uCX)/uCY;
D3DXMatrixPerspectiveFovLH( &matProj, Fov, fAspect, 0.1f, 100.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement