Jump to content
  • Advertisement
Sign in to follow this  
akira32

In MFC SDI,How to write D3D code

This topic is 4102 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

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]

Share this post


Link to post
Share on other sites
Advertisement
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);


Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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 );

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!