I am learning OpenGL and the tutorials (1, 2) I'm reading teach me that to scale/rotate/translate an object you have to know matrix multiplication. Why? Instead of 3x3 matrix you can use 6 floats: scale_x, scale_y, sin_a, cos_a, mov_x and mov_y. They would result in...
- Less GPU and CPU usage (matrix multiplication takes 9 multiplications and 6 additions while individual variables need 6 multiplications and 4 additions. Also, if you want to move object, instead of having to multiply whole matrix you get to only change values of two floats.
- Less memory bandwidth (1/3 cut!)
- Easier to manipulate (at least in C, no need for matrix manipulation functions)
- Easier information extraction to get object rotation or offset or scale
The only disadvantages that I know of are:
- You cannot change the order of transformations, most importantly, rotation around some point, not the origin of the coordinate plain. You can simulate it, though, by altering
mov_xandmov_yaccordingly. - More code. You could put them into an array though, but that would mean you would lose the ability to update them one by one and only could update them all or the beginning of array, not the middle or the end. I could be wrong on this, though.
Could someone tell me what am I missing?
Edit: added my shader below.
#version 330 layout (location = 0) in vec2 pos; layout (location = 1) in vec3 clr_in; uniform float osclx, oscly, osina, ocosa, omovx, omovy; uniform float msclx, mscly, msina, mcosa, mmovx, mmovy; float oldx, oldy, x, y; out vec3 clr_out; void main() { x = pos.x; y = pos.y; x = x * oscly; y = y * osclx; oldx = x; oldy = y; x = oldx * ocosa - oldy * osina; y = oldx * osina + oldy * ocosa; x = x + omovx; y = y + omovy; x = x * msclx; y = y * mscly; oldx = x; oldy = y; x = oldx * mcosa - oldy * msina; y = oldx * msina + oldy * mcosa; x = x + mmovx; y = y + mmovy; gl_Position = vec4(x, y, 0.0f, 1.0f); clr_out = clr_in; }