Hello.
Until now I’ve been using the deprecated functions for setting up my matrices, but now I wish to only use OpenGL 3.x. I think I’ve gotten the grasp of vertex buffers, vertex arrays, shaders, etc, so now I just need to get my matrices working.
My old code:
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(fieldOfView, (float)width / height, near, far);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
// 'e' stands for eye, 'c' stands for center, 'u' stands for up
GLU.gluLookAt(ex, ey, ez, cx, cy, cz, ux, uy, uz);
Earlier I just used the glTranslate/Rotate/Scale methods to move around my models. This works fine, but since none of the above functions are supported in OpenGL 3.x, I basically need a crash course in matrix operations. I’ve been reading around on the Internet and (I think) I understand; Different matrices are multiplied together and then finally multiplied with the game world coordinates in the vertex shader, but I’m having a hard time finding out what the different matrices actually do or represent. I’ve also heard that lighting should be done in between the projection matrix and the modelview matrix, but I’m just so confused about all these names/words. I don’t really understand what some of them represent or what they yield. What am I supposed to put in each matrix?
According to Swiftless I need 3 matrices in my vertex shader, which I believe older versions of OpenGL premultiplied together on the CPU, right? Would there be any benefit of having them split up? I’m guessing lighting here (which I won’t be doing in while, but still interested).
What is the best way of keeping track of the matrix data now that OpenGL’s matrix stack is deprecated? My own implementation of a matrix stack? I don’t think I need one. Are there any libraries for matrix operations (LWJGL)?
My biggest need is probably an explanation of what the different matrices do. So far I think I’ve figured out this at least:
View Matrix: The camera position and orientation?
Model Matrix: The current models position, orientation and scale?
Projection Matrix: Uuuh… Basically makes things smaller if they are far away?
Also, how would I send it to my shaders? Premultiplied? My game will most likely be GPU-limited so it’s probably best to premultiply some or all of the matrices, but which ones CAN I premultiply?
Ah, finally: I’ve heard that bones in skeleton animation are matrices. Is each bone multiplied with it’s parent?
Jeez, so many questions but try to bear with me. ;D