Sign in to follow this  

[Direct3D] Question about orthogonal projection / perpective

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

Hello,

I'm using Direct3D 9 in native C++, and I'm displaying textured quads on the screen using left & top position.

Right now, I'm using an orthogonal projection, like this:

D3DXMatrixOrthoLH (&matOrtho, (float) main_win.width, (float) main_win.height, -1000.0f, 1000.0f);
i_d3d_device->SetTransform (D3DTS_PROJECTION, &matOrtho);

Its working and the quads are displayed.

But now, I want to do some rotations of the quads along the Y axe for exemple, and have some perspective (the left side of the quad will be fading away, and the right side coming toward us), the problem is that the orthogonal projection flatten the perspective, and the 2 side have the same size...

So, I wanted to switch to a perspective projection, with this:

D3DXMatrixPerspectiveLH( &m_matProj, main_win.width, main_win.height, -1000.0f, 1000.0f );
i_d3d_device->SetTransform (D3DTS_PROJECTION, &matProj);

But, its not working, black screen ...

Any idea what is wrong ? thanks in advance :)

Share this post


Link to post
Share on other sites
Here is more code :

D3DXMATRIX matOrtho, m_matProj;
D3DXMATRIX matIdentity;

//D3DXMatrixOrthoLH (&matOrtho, (float) main_win.width, (float) main_win.height, 0.0f, 1.0f);
D3DXMatrixPerspectiveLH( &m_matProj, (float) main_win.width, (float) main_win.height, 0.0f, 1.0f );
D3DXMatrixIdentity (&matIdentity);
i_d3d_device->SetTransform (D3DTS_PROJECTION, &m_matProj);
i_d3d_device->SetTransform (D3DTS_VIEW, &matIdentity);
i_d3d_device->SetTransform (D3DTS_WORLD, &matIdentity);

Please :)

Share this post


Link to post
Share on other sites
You're setting the near-view plane to -1000.0f. Set it 1.0f while keeping the far-view plane at 1000.0f and check if it works. If it didn't, try replacing the D3DXMatrixPerspectiveLH function with this:


D3DXMatrixPerspectiveFovLH(&m_matProj,
D3DXToRadian(45),
(FLOAT)main_win.width / (FLOAT)main_win.height,
0.0f,
2000.0f);

Share this post


Link to post
Share on other sites
If you think about what wayoff said, because the near plane is behind the camera space origin, the "inside" of each plane is now outside.


A___B Any point p, inside the frustum is defined as A.x < p.x < B.x) for each y.
\ / As we pass origin, 0 , this becomes impossible because B.x < A.x.
o So, the near plane must be a positive value.
/ \

Share this post


Link to post
Share on other sites
I think that I need to read about Direct3D a little more, many key concept like the frustum and such are still difficult to me to understand.

I'll read some tutorials and I'm sure I'll level up :p thanks everyone for your help :)

Share this post


Link to post
Share on other sites

This topic is 2664 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this