Page 3 of 3

Re: Perspective Projection

Posted: Thu Jul 07, 2016 2:54 pm
by Benjamin100

Code: Select all

GLfloat projectionMatrix[]={(1/0.414),    0.0,   0.0,  0.0,
                             0.0,     (1/0.414),    0.0,  0.0,
                             0.0,  0.0,        (101/-99), (-200/-99),
                             0.0,  0.0,         -1.0,           0.0};
To be in the correct form in the shader, this SHOULD need to be transposed ALSO. But it only works if I DON'T transpose it.

Re: Perspective Projection

Posted: Thu Jul 07, 2016 3:18 pm
by dandymcgee
Benjamin100 wrote:

Code: Select all

GLfloat projectionMatrix[]={(1/0.414),    0.0,   0.0,  0.0,
                             0.0,     (1/0.414),    0.0,  0.0,
                             0.0,  0.0,        (101/-99), (-200/-99),
                             0.0,  0.0,         -1.0,           0.0};
To be in the correct form in the shader, this SHOULD need to be transposed ALSO. But it only works if I DON'T transpose it.
Because, the article I sourced that matrix from was an OpenGL article, and it was using column-major order to show matrices. As such, it is already transposed. Transposing it again puts it into row-major order.

The first few paragraphs of this article reiterate the point I'm making. It also has a ton of other useful information if you care:
http://www.scratchapixel.com/lessons/3d ... ion-matrix

In summary, OpenGL programmers write matrices in column-major order, and mathematicians write them in row-major order. So if you're reading an OpenGL book, don't transpose them. If you're reading a Wikipedia article, you'll probably have to transpose them. As stated previously, the reason for this has to do with how you declare arrays in C++ and OpenGL's assumption that the 2nd element in the array is second row, first column (column-major) rather than first row, second column (row-major).

It could have happened either way, it's just bad luck and ignorance that we're stuck with differing norms than the mathematicians in this case. All the more reason to use a math library, or write some wrappers yourself to abstract this nonsense away from your daily work.

Re: Perspective Projection

Posted: Thu Jul 07, 2016 8:38 pm
by Benjamin100
But I didn't put it in column major order. I put it in an array, which should transpose it. Then it would need transposed again to put it back in column major order.

Re: Perspective Projection

Posted: Thu Jul 07, 2016 8:46 pm
by Benjamin100
BOTH my translation and projection matrices are written in arrays. Those arrays are made in such a way that they would create row major matrices.
They both should need to be transposed to make the column major matrices that the arrays look like. If I transpose the translation matrix, it works. If I transpose the projection matrix, (making IT column form,) it does NOT work. They are both created using arrays. They are both made to APPEAR column major even though they need to be transposed to be columns. But when I transpose one it works, and the other only works when not transposed.

Re: Perspective Projection

Posted: Fri Jul 08, 2016 10:26 am
by dandymcgee
Benjamin100 wrote:BOTH my translation and projection matrices are written in arrays. Those arrays are made in such a way that they would create row major matrices.
They both should need to be transposed to make the column major matrices that the arrays look like. If I transpose the translation matrix, it works. If I transpose the projection matrix, (making IT column form,) it does NOT work. They are both created using arrays. They are both made to APPEAR column major even though they need to be transposed to be columns. But when I transpose one it works, and the other only works when not transposed.
In any case, you said it's working, right? I'd stop caring about it for now and come back later with a clear mind. Focusing on something like this for too long will drive you insane; if it works, just go with it for now. There are bigger fish. :)

Re: Perspective Projection

Posted: Sat Jul 30, 2016 8:46 pm
by Benjamin100
Well the matrices are working much better now, but I am absolutely sick of working on this obj file reading. It is just a pain needing to put everything in order, and making sure I set the right normal for each vertex and everything. Maybe I should just use a library. The thing I don't like about using somebody else's library is that they have control over it, and I need to learn their way of putting things. I don't know.

Re: Perspective Projection

Posted: Sun Jul 31, 2016 3:14 pm
by K-Bal
Use a library, it's not worth the hassle. Object files are also pretty limited and you will find yourself implementing import code for several formats.

I know that libgdx uses this import library: http://www.assimp.org/

Re: Perspective Projection

Posted: Fri Aug 05, 2016 12:12 am
by Benjamin100
I figured that I'd be using other files anyways since I can't imagine this format being very helpful for artists.
No use in trying to solve problems that have already been solved numerous times. After all, I want to do do graphics programming, not graphics file programming.

Re: Perspective Projection

Posted: Fri Aug 05, 2016 11:29 pm
by short
Benjamin100 wrote:After all, I want to do do graphics programming, not graphics file programming.
This made me chuckle.