PDA

View Full Version : matrices in c



sandbucket
07-30-2013, 08:18 AM
hi, i am trying to modify the position of an object using matrices. i define a matrix like this:
GLfloat matrix[] = {1, 0, 0, .25, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};

i then set the uniform matrix value using glUniformMatrix4fv(matrixloc, 1, GL_FALSE, matrix);

when i multiply the matrix by the vector in the vertex shader (gl_Position = Matrix * Vector) (my vector has a 1 in the w value) it doesnt draw the triangle. whats going on?

GClements
07-30-2013, 08:43 AM
hi, i am trying to modify the position of an object using matrices. i define a matrix like this:
GLfloat matrix[] = {1, 0, 0, .25, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};

i then set the uniform matrix value using glUniformMatrix4fv(matrixloc, 1, GL_FALSE, matrix);

If that's supposed to be equivalent to glTranslatef(0.25, 0, 0), then you need to pass GL_TRUE as the transpose parameter (or transpose the matrix itself).

By default, OpenGL assumes that matrices are in column-major order, so the 0.25 will be on the bottom row of the left-most column. For a translation, the X component should be in the top row of the right-most column.