Im using c++ 17 GLFW,GLEW, and glm for my game. I have rotations stored with quaternions. I rotate the players rotation by a quaternion and convert the players rotation to a vec3 later to get where they are facing. I try getting to yaw to move the player but the yaw isnt correct.
glm::eulerAngles returns a different euler angle then Id like to. I only rotate on the y axis but it returns back different axis that rotate up to the same thing.
glm::quat& q = gameobject->GetRotation();
float new_Yaw = (180.0f / 3.14159f) * glm::eulerAngles(q).y;
//Not giving correct values
std::cout << new_Yaw << std::endl;
float yaw = glm::yaw(q);
glm::vec3 dir(0.0f);
//std::cout << (yaw * (180.0f / 3.14159f)) << std::endl;
if (Input::IsKeyDown(GLFW_KEY_W)) {
dir.x -= sin(yaw);
dir.z += cos(yaw);
}else if (Input::IsKeyDown(GLFW_KEY_S)) {
dir.x += sin(yaw);
dir.z -= cos(yaw);
}
gameobject->transform.Translate(dir * speed);
//Player turning mouse
float turn_x = Time::delta_time * Input::delta_x;
float turn_y = Time::delta_time * Input::delta_y;
gameobject->transform.Rotate(glm::quat(glm::vec3(0.0f, turn_x, 0.0f)));
Also Tried using glm::yaw on my quaternion to get the yaw and it still isnt giving me a correct value.