In tutorials regarding the MD5Mesh format, like this one, we often see code like
float t = 1.0f - (q.x * q.x) - (q.y * q.y) - (q.z * q.z);
if (t < 0.0f) {
q.w = 0.0f;
} else {
q.w = -sqrt (t);
}
for computing the w-component of a unit quaternion given x, y, z
.
Why do we obtain w in this manner?