I’m trying to make the camera follow the car and the camera translation and rotation works fine, but the car transformations don’t quite work. If i translate and then rotate the car, the translations following a rotation don’t apply relative to the car’s position, they apply relative to the origin. This is the code i have for the car rendering :
model = glm::mat4(1.0f); model = glm::scale(model, glm::vec3(0.5f, 0.5, 0.5f)); model = glm::translate(model, modelSpeed); model = glm::rotate(model, glm::radians(modelAngle), glm::vec3(0, 1, 0)); //send model matrix data to shader glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model)); //create normal matrix normalMatrix = glm::mat3(glm::inverseTranspose(view*model)); //send normal matrix data to shader glUniformMatrix3fv(normalMatrixLoc, 1, GL_FALSE, glm::value_ptr(normalMatrix)); car.Draw(myCustomShader);
Do you guys know a way to make the car follow the camera whichever way I’m looking? Thanks a lot.