store matrices in column-major mode
This commit is contained in:
parent
64b76bd085
commit
a278d1843f
@ -52,9 +52,9 @@ void guMatrixMult(guMatrix4x4 *m, guMatrix4x4 *a, guMatrix4x4 *b)
|
|||||||
GLfloat v = 0.0;
|
GLfloat v = 0.0;
|
||||||
for (p = 0; p < 4; p++)
|
for (p = 0; p < 4; p++)
|
||||||
{
|
{
|
||||||
v += (*a)[i][p] * (*b)[p][j];
|
v += (*a)[p][i] * (*b)[j][p];
|
||||||
}
|
}
|
||||||
(*m)[i][j] = v;
|
(*m)[j][i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ void guMatrixTranslate(guMatrix4x4 *m, GLfloat x, GLfloat y, GLfloat z)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
(*m)[i][3] += (*m)[i][0] * x + (*m)[i][1] * y + (*m)[i][2] * z;
|
(*m)[3][i] += (*m)[0][i] * x + (*m)[1][i] * y + (*m)[2][i] * z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,10 +73,9 @@ void guMatrixScale(guMatrix4x4 *m, GLfloat x, GLfloat y, GLfloat z)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
GLfloat *base = &(*m)[i][0];
|
(*m)[0][i] *= x;
|
||||||
base[0] *= x;
|
(*m)[1][i] *= y;
|
||||||
base[1] *= y;
|
(*m)[2][i] *= z;
|
||||||
base[2] *= z;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,20 +96,20 @@ void guMatrixRotate(guMatrix4x4 *m, GLfloat angle,
|
|||||||
guMatrix4x4 mult;
|
guMatrix4x4 mult;
|
||||||
GLfloat oc = 1 - c;
|
GLfloat oc = 1 - c;
|
||||||
mult[0][0] = lx * lx * oc + c;
|
mult[0][0] = lx * lx * oc + c;
|
||||||
mult[0][1] = lx * ly * oc - lz * s;
|
mult[1][0] = lx * ly * oc - lz * s;
|
||||||
mult[0][2] = lx * lz * oc + ly * s;
|
mult[2][0] = lx * lz * oc + ly * s;
|
||||||
mult[0][3] = 0.0;
|
|
||||||
mult[1][0] = ly * lx * oc + lz * s;
|
|
||||||
mult[1][1] = ly * ly * oc + c;
|
|
||||||
mult[1][2] = ly * lz * oc - lx * s;
|
|
||||||
mult[1][3] = 0.0;
|
|
||||||
mult[2][0] = lx * lz * oc - ly * s;
|
|
||||||
mult[2][1] = ly * lz * oc + lx * s;
|
|
||||||
mult[2][2] = lz * lz * oc + c;
|
|
||||||
mult[2][3] = 0.0;
|
|
||||||
mult[3][0] = 0.0;
|
mult[3][0] = 0.0;
|
||||||
|
mult[0][1] = ly * lx * oc + lz * s;
|
||||||
|
mult[1][1] = ly * ly * oc + c;
|
||||||
|
mult[2][1] = ly * lz * oc - lx * s;
|
||||||
mult[3][1] = 0.0;
|
mult[3][1] = 0.0;
|
||||||
|
mult[0][2] = lx * lz * oc - ly * s;
|
||||||
|
mult[1][2] = ly * lz * oc + lx * s;
|
||||||
|
mult[2][2] = lz * lz * oc + c;
|
||||||
mult[3][2] = 0.0;
|
mult[3][2] = 0.0;
|
||||||
|
mult[0][3] = 0.0;
|
||||||
|
mult[1][3] = 0.0;
|
||||||
|
mult[2][3] = 0.0;
|
||||||
mult[3][3] = 1.0;
|
mult[3][3] = 1.0;
|
||||||
guMatrixMult(m, m, &mult);
|
guMatrixMult(m, m, &mult);
|
||||||
}
|
}
|
||||||
@ -133,12 +132,12 @@ void guMatrixFrustum(guMatrix4x4 *m,
|
|||||||
GLfloat tb = top - bottom;
|
GLfloat tb = top - bottom;
|
||||||
GLfloat fn = far - near;
|
GLfloat fn = far - near;
|
||||||
mult[0][0] = 2 * near / rl;
|
mult[0][0] = 2 * near / rl;
|
||||||
mult[0][2] = (right + left) / rl;
|
mult[2][0] = (right + left) / rl;
|
||||||
mult[1][1] = 2 * near / tb;
|
mult[1][1] = 2 * near / tb;
|
||||||
mult[1][2] = (top + bottom) / tb;
|
mult[2][1] = (top + bottom) / tb;
|
||||||
mult[2][2] = - (far + near) / fn;
|
mult[2][2] = - (far + near) / fn;
|
||||||
mult[2][3] = - 2 * far * near / fn;
|
mult[3][2] = - 2 * far * near / fn;
|
||||||
mult[3][2] = -1.0;
|
mult[2][3] = -1.0;
|
||||||
guMatrixMult(m, m, &mult);
|
guMatrixMult(m, m, &mult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,8 +158,8 @@ void guPerspective(guMatrix4x4 *m, GLfloat fovy, GLfloat aspect,
|
|||||||
mult[0][0] = f / aspect;
|
mult[0][0] = f / aspect;
|
||||||
mult[1][1] = f;
|
mult[1][1] = f;
|
||||||
mult[2][2] = (far + near) / nf;
|
mult[2][2] = (far + near) / nf;
|
||||||
mult[2][3] = (2 * far * near) / nf;
|
mult[3][2] = (2 * far * near) / nf;
|
||||||
mult[3][2] = -1.0;
|
mult[2][3] = -1.0;
|
||||||
guMatrixMult(m, m, &mult);
|
guMatrixMult(m, m, &mult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,12 +181,13 @@ void guOrtho(guMatrix4x4 *m,
|
|||||||
GLfloat tb = top - bottom;
|
GLfloat tb = top - bottom;
|
||||||
GLfloat fn = far - near;
|
GLfloat fn = far - near;
|
||||||
mult[0][0] = 2 / rl;
|
mult[0][0] = 2 / rl;
|
||||||
mult[0][3] = - (right + left) / rl;
|
mult[3][0] = - (right + left) / rl;
|
||||||
mult[1][1] = 2 / tb;
|
mult[1][1] = 2 / tb;
|
||||||
mult[1][3] = - (top + bottom) / tb;
|
mult[3][1] = - (top + bottom) / tb;
|
||||||
mult[2][2] = -2 / fn;
|
mult[2][2] = -2 / fn;
|
||||||
mult[2][3] = - (far + near) / fn;
|
mult[3][2] = - (far + near) / fn;
|
||||||
mult[3][3] = 1.0;
|
mult[3][3] = 1.0;
|
||||||
|
guMatrixMult(m, m, &mult);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *guGetShaderLog(GLuint id)
|
char *guGetShaderLog(GLuint id)
|
||||||
|
@ -188,8 +188,8 @@ bool init(int width, int height)
|
|||||||
glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0);
|
glUniform4f(diffuse_loc, 1.0, 0.6, 0.0, 1.0);
|
||||||
glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0);
|
glUniform4f(specular_loc, 1.0, 1.0, 1.0, 1.0);
|
||||||
glUniform1f(shininess_loc, 85.0);
|
glUniform1f(shininess_loc, 85.0);
|
||||||
glUniformMatrix4fv(projection_loc, 1, GL_TRUE, &projection[0][0]);
|
glUniformMatrix4fv(projection_loc, 1, GL_FALSE, &projection[0][0]);
|
||||||
glUniformMatrix4fv(modelview_loc, 1, GL_TRUE, &modelview[0][0]);
|
glUniformMatrix4fv(modelview_loc, 1, GL_FALSE, &modelview[0][0]);
|
||||||
|
|
||||||
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
||||||
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user