I have a camera class that contains a position, a pitch, and a yaw (the pitch and the yaw correspond to y and x rotation values). I want to implement a lookAt function that takes a vector and the function changes the pitch and yaw so it's looking at that point in space. However, I cannot seem to find the math equation to do it (various ones online, none seem to work). How would I be able to implement it?
Here's an example of what I mean:
struct Camera
{
Vec3 position;
float pitch, yaw;
void lookAt(Vec3 center)
{
//????
}
mat4x4 toTransform() //How I convert the values to a matrix (if this is relevant)
{
return CreateLookAtMatrix
position,
position + Vec3(cos(pitch)*sin(yaw), sin(pitch), cos(pitch)*cos(yaw)),
Vec3(0.0f, 1.0f, 0.0f)
);
}
}