Special Projection (math help)
Hi,
I need to render some objects using a special projection, that is a like ortho in the x direction and like perspective in the y direction.
I've been looking for the math behind this issue, and I finally arrived to this page
http://www.codeguru.com/Cpp/misc/misc/math/article.php/c10123/
which gives a nice introduction.
I thought it would be easy to come up with the matrix I need, but I was wrong. The equations used to derive each matrix (ortho an persperctive) differ in the w coordinate, so I can't figure out how to mix them.
Can anyone give me some insight on this, or suggest o book or link where to look?
Thanks a lot
if i recall from my Computer Graphics learning the w parameter is usally set to 1
but then agian maybe i am wrong
but then agian maybe i am wrong
I think you're probably going to have to do some digging in early software renderers to find documentation on how projection matrices are built.
As far as OpenGl is concerned, you should be able to use it's calculations to simplify what you're trying to do. GL generates both projection and ortho matrices. You should be able to combine the results to get what you want. To my knowledge, the perspective matrix maps the result of the modelview to the screen. That said, the resulting vector is two dimentional. Now consider matrix multiplication of the projection matrix with a vector that has been transformed by the modelview matrix (the resulting screen coordinates are x' and y'):
According to the multiplication:
x' = a1*x + a2*y + a3*z + a4*w
y' = b1*x + b2*y + b3*z + b4*w
In your case, you want row a to come from an ortho matrix and row b to come from a projection matrix. It shouldn't matter what c and d are because the result should always be 0 (ie monitors do not have a z or w dimention). I think you should do the following:
- generate and store an ortho matrix
- generate and store a projection matrix
- replace the first row of the projection matrix with the values from the ortho matrix
- load the result as the new projection matrix.
You're going to have to do some looking into how OpenGL indexes it's matrices (the red book should cover this). I think it's something like:
|0 4 8 12|
|1 5 9 13|
|2 6 10 14|
|3 7 11 15|
Also, a hand calculation to prove your code would probably be a good idea (if this is for something important). Good luck; would like to see the results if it's convienient :).
Cheers,
- llvllatrix
As far as OpenGl is concerned, you should be able to use it's calculations to simplify what you're trying to do. GL generates both projection and ortho matrices. You should be able to combine the results to get what you want. To my knowledge, the perspective matrix maps the result of the modelview to the screen. That said, the resulting vector is two dimentional. Now consider matrix multiplication of the projection matrix with a vector that has been transformed by the modelview matrix (the resulting screen coordinates are x' and y'):
|a1 a2 a3 a4||x| |x'||b1 b2 b3 b4||y| = |y'||c1 c2 c3 c4||z| |0 ||d1 d2 d3 d4||w| |0 |
According to the multiplication:
x' = a1*x + a2*y + a3*z + a4*w
y' = b1*x + b2*y + b3*z + b4*w
In your case, you want row a to come from an ortho matrix and row b to come from a projection matrix. It shouldn't matter what c and d are because the result should always be 0 (ie monitors do not have a z or w dimention). I think you should do the following:
- generate and store an ortho matrix
- generate and store a projection matrix
- replace the first row of the projection matrix with the values from the ortho matrix
- load the result as the new projection matrix.
You're going to have to do some looking into how OpenGL indexes it's matrices (the red book should cover this). I think it's something like:
|0 4 8 12|
|1 5 9 13|
|2 6 10 14|
|3 7 11 15|
Also, a hand calculation to prove your code would probably be a good idea (if this is for something important). Good luck; would like to see the results if it's convienient :).
Cheers,
- llvllatrix
I read that document over a few times -- good read. I'm wondering, though, what you mean exactly by perspective in the y direction? That document takes the approach of defining your volume to project to the screen, so what does your volume look like in this case? If you can't visualize what the volume looks like, then can you describe specifically how you'd like a point to project?
My guess at what you wanted was a projection of all x values with no special transformation, so just x' = x (excluding the viewport stuff). Do you want the y values to be projected like normal perspective which is based on the z? i.e. a point (x1, y, z1) maps to a different y value than point (x2, y, z2) because their z's differ? If I can visualize this correctly, then objects will be squished vertically as they go further towards z-far?
My guess at what you wanted was a projection of all x values with no special transformation, so just x' = x (excluding the viewport stuff). Do you want the y values to be projected like normal perspective which is based on the z? i.e. a point (x1, y, z1) maps to a different y value than point (x2, y, z2) because their z's differ? If I can visualize this correctly, then objects will be squished vertically as they go further towards z-far?
Quote: Original post by llvllatrix
I think you're probably going to have to do some digging in early software renderers to find documentation on how projection matrices are built.
As far as OpenGl is concerned, you should be able to use it's calculations to simplify what you're trying to do. GL generates both projection and ortho matrices. You should be able to combine the results to get what you want. To my knowledge, the perspective matrix maps the result of the modelview to the screen. That said, the resulting vector is two dimentional. Now consider matrix multiplication of the projection matrix with a vector that has been transformed by the modelview matrix (the resulting screen coordinates are x' and y'):
*** Source Snippet Removed ***
According to the multiplication:
x' = a1*x + a2*y + a3*z + a4*w
y' = b1*x + b2*y + b3*z + b4*w
In your case, you want row a to come from an ortho matrix and row b to come from a projection matrix. It shouldn't matter what c and d are because the result should always be 0 (ie monitors do not have a z or w dimention). I think you should do the following:
- generate and store an ortho matrix
- generate and store a projection matrix
- replace the first row of the projection matrix with the values from the ortho matrix
- load the result as the new projection matrix.
You're going to have to do some looking into how OpenGL indexes it's matrices (the red book should cover this). I think it's something like:
|0 4 8 12|
|1 5 9 13|
|2 6 10 14|
|3 7 11 15|
Also, a hand calculation to prove your code would probably be a good idea (if this is for something important). Good luck; would like to see the results if it's convienient :).
Cheers,
- llvllatrix
I recently tried this method with marginal success. I'm still fairly convinced, however, that you should be able to combine the generated matrices to produce the desired result. Will continue to look into the problem.
Cheers,
- llvllatrix
Well the thing is I noticed I don't need this projection, but the problem is still very intresting.
The volume is very similar to a frustrum, but instead of tracing rays from a single point (the view point) to create a pyramid y need to use a line.
I've been reading about things I remember from college, since I think it should be possible to map any convex volume definde by 6 planes into the canonical volume. Anyway I wasn't able to get it so far.
I'm trying to figure out this mapping using 2D figures, and then I'll try to generalize the results to 3D. I'm thinking of it like this: suppose you have a quadrilateral, and you want to map every point (x,y) of this quadrilateral into a corresponding point (x',y') of a "canonical" square. It's easy if the original quadrilateral is a parallelogram, but it gets harder for other figures.
Thanks for the interest so far.
Regards
The volume is very similar to a frustrum, but instead of tracing rays from a single point (the view point) to create a pyramid y need to use a line.
I've been reading about things I remember from college, since I think it should be possible to map any convex volume definde by 6 planes into the canonical volume. Anyway I wasn't able to get it so far.
I'm trying to figure out this mapping using 2D figures, and then I'll try to generalize the results to 3D. I'm thinking of it like this: suppose you have a quadrilateral, and you want to map every point (x,y) of this quadrilateral into a corresponding point (x',y') of a "canonical" square. It's easy if the original quadrilateral is a parallelogram, but it gets harder for other figures.
Thanks for the interest so far.
Regards
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement