glm::mat4 modelMatrix;
glm::mat4 modelViewMatrix;
glm::mat4 modelViewProjectionMatrix;
glm::mat3 normalMatrix;
glm::mat4 ProjectionMatrix;
glm::mat4 viewMatrix;
ProjectionMatrix = glm::perspective(60.0f, ratio, 0.1f, 4096.0f); //setup projection
viewMatrix = glm::lookAt(glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, 1.0, 0.0)); //set view camera at 0,0,0 looking forward into the z-axis
void coLoadIdentity()
{
modelMatrix = glm::mat4(1.0f);
//glLoadIdentity();
}
void coRotatef(float angle, float x, float y, float z)
{
modelMatrix = glm::rotate(modelMatrix, angle, glm::vec3(x, y, z));
//glRotatef(angle, x, y, z);
}
void coTranslatef(float x, float y, float z)
{
modelMatrix = glm::translate(modelMatrix, glm::vec3(x, y, z));
//glTranslatef(x, y, z);
}
inline void reApplyTransform(vec viewer, float yaw, float pitch) //used to apply two operations with one function for simplicity
{
coLoadIdentity();
coRotatef(pitch, 1.0, 0.0, 0.0);
coRotatef(yaw, 0.0, 1.0, 0.0);
coTranslatef(viewer.x, viewer.y, viewer.z);
}
void updateMatrices() //called before something is drawn and after transformations have been applied
{
modelViewMatrix = modelMatrix * viewMatrix;
modelViewProjectionMatrix = modelViewMatrix * ProjectionMatrix;
normalMatrix = glm::inverseTranspose(glm::mat3(modelViewMatrix));
glUniformMatrix4fv(mvmat_loc, 1, false, glm::value_ptr(modelViewMatrix));
glUniformMatrix4fv(mvpmat_loc, 1, false, glm::value_ptr(modelViewProjectionMatrix));
glUniformMatrix3fv(nmat_loc, 1, false, glm::value_ptr(normalMatrix));
}
vertex shader:
void main(void)
{
vnormal = normalize(normalMatrix * normal);
vec3 ntangent = normalize(normalMatrix * tangent.xyz);
vec3 bitangent = cross(vnormal, ntangent) * -tangent.w;
TBN = mat3(ntangent, bitangent, vnormal);
v = vec3(modelViewMatrix * vec4(position, 1.0));
VaryingTexCoord0 = vec4(vec3(texCoord, 0), 0);
gl_Position = modelViewProjectionMatrix * vec4(position, 1.0);
}
anybody spot anything obviously wrong?