openglmathbasis

A confusion about space transformation in OpenGL


In the book of 3D graphics for game programming by JungHyun Han, at page 38-39, it is given that

the basis transformation matrix from e_1, e_2, e_3 to u,v,n is enter image description here

However, this contradicts with what I know from linear algebra. I mean shouldn't the basis-transformation matrix be the transpose of that matrix ?

Note that the author does his derivation, but I couldn't find where is the missing point between what I know and what the author does.

The code: Vertex Shader:

#version 330
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;

uniform vec3 cameraPosition;
uniform vec3 AT;
uniform vec3 UP;
uniform mat4 worldTrans;

vec3 ep_1 = ( cameraPosition - AT )/ length(cameraPosition - AT);
vec3 ep_2 = ( cross(UP, ep_1) )/length( cross(UP, ep_1 )); 
vec3 ep_3 = cross(ep_1, ep_2);

vec4 t_ep_1 = vec4(ep_1, -1.0f);
vec4 t_ep_2 = vec4(ep_2, cameraPosition.y);
vec4 t_ep_3 = vec4(ep_3, cameraPosition.z);
mat4 viewTransform = mat4(t_ep_1, t_ep_2, t_ep_3, vec4(0.0f, 0.0f, 0.0f, 1.0f));

smooth out vec4 fragColor;
void main()
{
    gl_Position = transpose(viewTransform) * position;
    fragColor = color;
}
)glsl";

Inputs:

GLuint transMat = glGetUniformLocation(m_Program.m_shaderProgram, "worldTrans");
    GLfloat dArray[16] = {0.0};
    dArray[0] = 1;
    dArray[3] = 0.5;
    dArray[5] = 1;
    dArray[7] = 0.5;
    dArray[10] = 1;
    dArray[11] = 0;
    dArray[15] = 1;
    glUniformMatrix4fv(transMat, 1, GL_TRUE, &dArray[0]);
    GLuint cameraPosId = glGetUniformLocation(m_Program.m_shaderProgram, "cameraPosition");
    GLuint ATId = glGetUniformLocation(m_Program.m_shaderProgram, "AT");
    GLuint UPId = glGetUniformLocation(m_Program.m_shaderProgram, "UP");
    const float cameraPosition[4] = {2.0f, 0.0f, 0.0f};
    const float AT[4] = {1.0f, 0.0f, 0.0f};
    const float UP[4] = {0.0f, 0.0f, 1.0f};
    glUniform3fv(cameraPosId, 1, cameraPosition);
    glUniform3fv(ATId, 1, AT);
    glUniform3fv(UPId, 1, UP);

Solution

  • Apparently, the change of basis in a vector space does changes the vectors in that vector space, and this is not what we want in here.

    Therefore, the mathematics that I was applying does not valid in here.

    To understand more about why we use the matrix that I have given in the question, please see this question.