I'm trying to get a lookAt function to work, and I've had some success:
public virtual void LookAt(Vector3 point)
{
Vector3 fw = Forward;
Vector3 delta = (point - Position).Normalized();
if (delta.LengthSquared > 0)
{
Vector3 axis = Vector3.Cross(delta, fw);
float angle = Vector3.CalculateAngle(delta, fw);
if (angle > 0)
{
angle *= -Math.Sign(Vector3.Dot(Vector3.Cross(axis, fw), delta));
Rotation *= Quaternion.FromAxisAngle(axis.Normalized(), angle);
}
}
}
This works, but it can't take into account that I don't want any roll. So the direction is correct, but I need to fix the roll of my camera. Now, I know I can rotate it by creating a Quaternion from AxisAngle, but I don't know how to get the angle between the current and upright position!?
edit: Using matrix.lookAt now and converting to quaternion.