I am trying to render a 3d model of a bmx bike.
The problem is, when I use the lib3ds mesh matrices, the bike renders completely wrong with bike components drawing all over the place.
It almost works when I don't use the mesh matrices from the lib3ds file, but some bike components are displayed incorrectly, so I probably need to use them.
I have checked the values of the mesh matrices and they are not identity matrices.
I use the following code to store the modified matrix for a mesh of the bike:
float meshMat[4][4];
lib3ds_matrix_copy(meshMat, mesh->matrix);
lib3ds_matrix_inv(meshMat);
pMesh->m_matTransformationMatrix = glm::mat4(
meshMat[0][0], meshMat[0][2], meshMat[0][1], meshMat[0][3],
meshMat[1][0], meshMat[1][2], meshMat[1][1], meshMat[1][3],
meshMat[2][0], meshMat[2][2], meshMat[2][1], meshMat[2][3],
meshMat[3][0], meshMat[3][2], meshMat[3][1], meshMat[3][3]
);
I use the following code when rendering a mesh of the bike:
glUniformMatrix4fv(glGetUniformLocation(getGameEngine()->m_uiProgram1, "model"), 1, GL_FALSE, glm::value_ptr(pMesh->m_matTransformationMatrix));
I use this glsl code for my vertex shader:
#version 330
in vec3 in_position;
uniform mat4 camera;
uniform mat4 model;
void main(void)
{
gl_Position = camera * model * vec4(in_position,1);
}
I'm currently not using my matrix (pos, rot & scale) for the bike, to less complicate things, so I'm only using the matrix from lib3ds currently.
I have switched y and z for all 4 vectors in the lib3ds matrix, because I have Y and Z switched in OpenGL.
I see that many examples on the net use glMultMatrix but that is an outdated OpenGL function, I am using the model in the GPU shaders.
Can anyone help?
If you need to see more code, just ask and I'll provide it.
Thanks,
Mex