Blueprint Quaternion Library

I was trying to figure out how to make a quat lookat function (-z) but running into some issues (please apologize the cringyness of my mathematical ignorance):

Making a quat from XZ or YZ only rotates the origin along one axis.

X axis Y axis


Composing the two quats results in the origin performing a cool breakdance


Making the quat from Z flips the X & Y axis at the 180 degrees mark (Gimbal Lock?)

______________________________________________________________________________

Averaging the axis works for the most part but there are target locations that prompt the origin’s signature breakdance


I’ve been trying to implement something along these lines, but so far have failed:

Quaternion lookAt(const Vector3f& sourcePoint, const Vector3f& destPoint, const Vector3f& front, const Vector3f& up)
{
Vector3f toVector = (destPoint - sourcePoint).normalized();
//compute rotation axis
Vector3f rotAxis = front.cross(toVector).normalized();
if (rotAxis.squaredNorm() == 0)
rotAxis = up;
//find the angle around rotation axis
float dot = VectorMath::front().dot(toVector);
float ang = std::acosf(dot);
//convert axis angle to quaternion
return Eigen::AngleAxisf(rotAxis, ang);
}


I am currently testing other methods based on adding to the quat rotation but the solutions so far represent the epitome of spaghettification and are anything but elegant.