Quote:Original post by 31337noob
do you?
Yes, in part. (Sorry, I was busy yesterday.)
Perhaps I lack enough knowledge of what you are doing with your app. However, I assume you are making a GUI, maybe a kind of 2D overlay or something similar?
You set-up a perspective projection. As you'll already know, perspective projections do a depth scaling; there is only one specific distance where the depth scaling is 1. Now it depends: Either you want to have your GUI element like a bill board integrated into the scene. That is, it faces always the camera, but it should be hidden by "normal" 3D scene elements (say, a tree trunk in front of the button should hide it). Then using perspective transformation is ok. However, in this case you have to consider perspective depth shortening also for your mouse click, since the click occurs onto the plane where depth shortening is 1 but does track all depth values on a straight line _not_ perpendicular to the screen! In other words, in such a case you have to scale your click co-ordinates depending on the GUI element's depth value before comparing them with the button co-ordinates.
Or (the more likely case): Your GUI is always in front of the 3D scene, like an overlay (e.g. a HUD) or a GUI even without 3D in behind. Your wish is to draw 2D GUI elements with pixel accuracy. (All of the following belongs to this case).
In such case I suggest not to use the perspective projection at all (also it is possible, too), but to use the orthogonal projection. This kind of projection has the advantage that it does not show any depth scaling. You could set it up using the D3DXMatrixOrthoLH function. Without proven, I assume something like
D3DXMatrixOrthoLH(&projMatrix,widhtInPixels,heightInPixels,-1,1);
should be possible (you could also take into account of using the "OffCenter" variant of this routine).
However, in the case of ortho projection you also have to set-up a suitable view matrix. I suggest the view matrix to do 2 things (you have to ignore the second thing if you use the "OffCenter" variant of projection): mirror the y axis since you want the y co-ordinate system of the GUI to grow from top to bottom, right?
D3DXMatrixScaling(&viewScale,1,-1,1);
computes such a matrix. But notice that doing so will probably require texture co-ordinates to be adapted, too). You also wants the origin to be located in the upper left corner, instead of the center of the screen, so you also have to translate the view by
D3DXMatrixTranslation(&viewTranslate,widhtInPixels/2,0.5f*heightInPixels/2,0);
(please notice that I write this from mind, not copying it from a tested app).
After setting up the view matrix from the proper product of those stuff above, it should be possible to push GUI geometry in a co-ordinate system (0,0,0) in the upper left and (widht-1,height-1,0) in the lower right corner. Render the GUI elements without depth test and in back to front order to get the overlapping right.
[Edited by - haegarr on December 23, 2005 4:15:35 AM]