Skip to main content
gamedev.net
🔒 Locked

2D like basic task

Started by vmware Mar 31, 2009 at 8:49 AM 6 replies 950+ views
Original Post
vmware
vmware
Hi I am relatively new to DirectX programming. I have a box that I can move right, left, down and up in sort of 2D. I achieve this using the following code. My problem and question is that if I use the code within section 2 this results in a two-point perspective transformation which isn't good for me. By this I mean that objects far away from the center of sight distort. What I would like instead is a sort of 1-point perspective which could imitate a 2-dimensional room. But if I comment out the 3 rows within section 2, nothing will appear. // section 1 D3DXVECTOR3 vEyePt( eyeX, eyeY,-5.0f ); D3DXVECTOR3 vLookatPt( eyeX, eyeY, 0.0f ); D3DXVECTOR3 vUpVec( eyeX, eyeY + 100, -5.0f); D3DXMATRIXA16 matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); // section 2 D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); Thanks for any piece of help.
vmware
vmware
I have now tried you suggestion, it doesn't work.

When "my eyes" move more and more right, the box still distorts.
As you can see here:
demo

D3DXMatrixOrthoOffCenterLH(&matProj,-10,10,-10,10,1,100);
vmware
vmware
I don't think that my D3DXMatrixLookAtLH parameters are incorrect.
Do you?
Evil Steve
Evil Steve
You're definitely not calling D3DXMatrixPerspectiveFovLH any more? That sort of distortion should be avoided with D3DXMatrixOrthoOffCenterLH.

Also, is your backbuffer the same size as your client rect (I.e. are you calling AdjustWindowRect() to get the size to pass to CreateWindow())? "Strange things" happen if you have a different sized backbuffer and client area.
vmware
vmware
I'm not calling D3DXMatrixPerspectiveFovLH any more.

Resizing the window does a different kind of distortion:
demo2
Evil Steve
Evil Steve
Ah, I see your view matrix is a bit odd - your "up" vector isn't just up, it's up and back a bit, so the camera is pitched up. You probably want:
D3DXVECTOR3 vEyePt(eyeX, eyeY, -5.0f);D3DXVECTOR3 vLookatPt(eyeX, eyeY, 0.0f);D3DXVECTOR3 vUpVec(0, 1, 0);D3DXMATRIXA16 matView;D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
vmware
vmware
Ah, thanks.
It works properly now.

Anyway, my approach to the up vector was some way logical, too.
:-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.