Jump to content
  • Advertisement
Sign in to follow this  
ZeDuS

directx matrices

This topic is 4616 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 my app i need to set the projection matrix myself (meaning i CAN'T use D3DXMatrixPerspectiveFovLH) i went to the documentation that comes with directx and read about D3DXMatrixPerspectiveFovLH and this is what they say:
 xScale     0          0               0
0        yScale       0               0
0          0       zf/(zf-zn)         1
0          0       -zn*zf/(zf-zn)     0
where:
yScale = cot(fovY/2)

xScale = aspect ratio / yScale

when i use it it seems to be completely wrong! i can only make it work this way: Change #1: i do xScale = yScale / aspect ratio (and not the other way as they say) Change #2: i negate xScale. that's the only way i get visual output, but i get it ofcourse mirrored on the x axis ... can anyone here please help me on this ?

Share this post


Link to post
Share on other sites
Advertisement
cot(x) = 1 / tan(x). Do you do it that way ?
I ask because the first time I read this I thought cot(x) was a typo and that it was cos(x).

I also found this one :

h = cos(fov/2) / sin(fov/2);
w = h / aspect;

2*zn/w 0 0 0
0 2*zn/h 0 0
0 0 zf/(zf-zn) 1
0 0 zn*zf/(zn-zf) 0

Share this post


Link to post
Share on other sites
like you, for cot i used cos/sin.

i'll try the projection matrix you offered, i hope it will work ;)

thanks :)

Share this post


Link to post
Share on other sites
The matrix you got from D3DXMatrixPerspectiveFovLH looks correct. Make sure you are doing the multiplying correctly. It seems that for some reason your code works when you multiply by the inverse (or something like that) of the projection matrix.

BTW, why can't you use D3DXMatrixPerspectiveFovLH?

Share this post


Link to post
Share on other sites
The reason i need to use the directx matrix is that my engine supports both directx and opengl, being that way the engine is an abstraction above both of those graphcis apis, so i want both outputs to be perfectly identical so i want to completely control what happens inside all the projection/modelview etc...

Share this post


Link to post
Share on other sites
Are you aware that GL and D3D utilize different matrix representations, and if so are you correctly compensating?

Share this post


Link to post
Share on other sites
Quote:
Original post by Ravyne
Are you aware that GL and D3D utilize different matrix representations, and if so are you correctly compensating?


i'm aware that it's left handed verses right handed, and i negate the z value of coordniates, but nothing more.

am i missing something ?

Share this post


Link to post
Share on other sites
Yes, AFAIK OpenGL matrices are in column-major form, where the translation components tx, ty, tz occupy elements 13, 14 and 15 of the matrix (with respect to a 16 element, single-dimentional array containing the matrix).

DirectX, on the other hand, uses row-major form, where the translation components tx, ty, tz occupy elements 4, 8 and 12 of the matrix. D3D matrices are the transpose of equivilant GL matrices.

| 01 02 03 04 |
| 05 06 07 08 |
| 09 10 11 12 |
| 13 14 15 16 |

Share this post


Link to post
Share on other sites
Also note that the screen-space z-axis bounds are different between OpenGL and DirectX (as indicated by JohnBolton)

In DirectX the near-plane is z = 0 and the far-plane is z = 1
In OpenGL the near-plane is z = -1 and the far-plane is z = 1

I can't remember the exact changes you have to make to the projection matrix to account for this but they're fairly simple (a sign change and a multiplication if I remember correctly).

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!