views:

164

answers:

2

Hi,

I want to project a grid on the xz-plane like shown here: http://habibs.files.wordpress.com/2009/07/2-1.jpg

To do that, I created a vertex grid with x and z range [-1|1]. In the shader I multiply the xz screen coordinate of a vertex with the inverse of the View-Projection matrix. Then I want to adjust the height, depending on the new world xz coordinates and finally I transform these coordinates back to screenspace by multiplying them with the View-Projection matrix.

I dont know why, but I get a very strange plane shown on the screen. Are the mathematical oprations I use correct?

Best, erik

A: 

The grid that you initially create, is that in projection space or actual screen co-ords? It sounds like it is in projection space since you only transform it with the inverse of the view-projection matrix to get into world co-ords. I think you need to include the "Window" matrix too i.e. transform them by the inverse of the View-Projection-Window matrix (and similarly on the way back to screen co-ords).

Edit:

I'm probably not understanding exactly what it is you're trying to do so here's some questions back. :)

Are you trying to take the grid that's shown in the screenshot in your question and project that onto world z-x co-ordinates? If so, then why do you start with a grid of z-x values? Also, if you apply an inverse view matrix to those then surely you would end up with a line since the camera looks along z although your second screenshots show that you are getting a plane. I'm a bit confused.

Troubadour
A: 

Hm. I don't really have a windows matrix. What I just did is changing the grid coordinates range to [0|1] (for testing) and multiplying the grid coordinates with the inverse view matrix. I get the following output: http://img229.imageshack.us/img229/3033/grid1.png Unfortunately the white square does not scale when zoming in or out and it does not center when rolling the camera around the horizontal axis: http://img229.imageshack.us/img229/107/grid2.png

Why that?

Best, erik

Heinrich
Please edit your original post rather than answering your own question.
Goz