Hi everyone.
I’m trying to make my model to rotate to the direction my camera is looking at, Similar to what it’s in comon games.
So, I can freely rotate my camera arround the model, then when i Play “W” I want my model to rotate to the direction my camera is pointing.
I already have the camera working. Rotating the Model is the problem.
I already managed to get the angle between my model’s Front Axis and my camera Front axis projected in xz Plane where my model is. by :
float d =
glm::degrees(glm::asin(glm::dot(glm::normalize(cameraFrontDir),
glm::normalize(Front))));
I’ve seen that this angle d is correct.
I’ve trying to compute Euler Angle and rotate the model In the Yaw Angle. But this is not working.
this function runs whenever I press W.
cameraFrontDir.y = Front.y;
float d = glm::degrees(glm::asin(glm::dot(glm::normalize(cameraFrontDir), glm::normalize(Front))));
//d = d - 90;
//std::cout << "CameraDir x : " << cameraFrontDir.x << std::endl;
//std::cout << "CameraDir y : " << cameraFrontDir.y << std::endl;
//std::cout << "CameraDir z : " << cameraFrontDir.z << std::endl;
//playerTransform->rotate(glm::vec3(0, 1, 0), d);
std::cout << " D: " << glm::floor(d) << std::endl;
std::cout << "Front x : " << Front.x << std::endl;
std::cout << "Front y : " << Front.y << std::endl;
std::cout << "Front z : " << Front.z << std::endl;
Yaw = d;
updateDirections();
Yaw = 0;
and UpdateDirections is :
void PlayerInputs::updateDirections() {
glm::vec3 front;
front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
front.y = sin(glm::radians(Pitch));
front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
Front = normalize(front);
Right = glm::normalize(glm::cross(Front, Up));
localUp = glm::normalize(glm::cross(Right, Front));
playerTransform->rotate(localUp,Yaw);
}