View Full Version : eye-space lighting

okapota

07-10-2002, 11:11 PM

ok, its a basic question, but i dont understand it. in order to perform eye-space lighting, i need to transform my vertex with the modelview matrix to eye space, and it's normal with the modelviewIT matrix. but when i look at the code of some programs, i notice they transpose the modelview matrix, and only inverse the modelviewIT. i mean like this-

MatrixInverse(&modelViewIT, &modelView);

//and then-

MatrixTranspose(&modelView);

so, why is it? should i first transpose and than inverse? should i transpose the modelview and only inverse the second? i thought i should take the modelview as is, and than inverse and than transpose.

Dan82181

07-11-2002, 06:23 AM

Well, OpenGL stores it's matrices in column major order, like so...

|1 5 9 13|

|2 6 10 14|

|3 7 11 15|

|4 8 12 16|

Whereas in linear algebra class, and in general matrix arithmatic, matrices are usually stored in row major order, like so...

|1 2 3 4 |

|5 6 7 8 |

|9 10 11 12|

|13 14 15 16|

So functions like glMultMatrix{f|d}, if you are storing your matrix in row major, you have to transpose it before you send to glMultMatrix, or else you'll be multiplying by the transpose. And calling

glGetDoublev(GL_MODELVIEW_MATRIX, &MV);

will return the modelview matrix transposed. So you'd have to transpose it yourself, or take that into consideration with your formulas when doing your matrix arithmatic. So if you have the modelview matrix in row major, and you calculate the inverse only, and then send it to OpenGL, it gets transposed, so then you have the inverse-transpose. Does that make sense to you?

There is the GL_ARB_transpose_matrix extension, you could try to take a look at that.

Dan

okapota

07-11-2002, 09:31 AM

thanks. i think i double transposed the inverse model view, i hope it is my only mistake.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.