【发布时间】:2018-08-16 20:44:32
【问题描述】:
我的 slerp 程序如下。根据我的阅读,对 > 0 的检查应该处理它,因此它总是采用最短路径。但它永远不会。在我穿过“极点”的情况下,四元数会翻转并产生具有 NAN 值的角度。
quat quat::slerp(quat dest, float t)
{
const quat &from = *this;
static const double epsilon = 0.0001;
double theta, cosTheta, sinTheta;
double p, q;
cosTheta = from.x*dest.x + from.y*dest.y + from.z*dest.z + from.w*dest.w;
if(cosTheta < 0.0)
{
dest = { -from.x, -from.y, -from.z, -from.w };
cosTheta = -cosTheta;
}
if((1.0-fabs(cosTheta)) > epsilon)
{
theta = acos(cosTheta);
sinTheta = sin(theta);
q = sin((1-t) * theta) / sinTheta;
p = sin(t*theta) / sinTheta;
}
else
{
q = 1-t;
p = t;
}
quat qo;
qo.w = (float)((q * from.w) + (p * dest.w));
qo.x = (float)((q * from.x) + (p * dest.x));
qo.y = (float)((q * from.y) + (p * dest.y));
qo.z = (float)((q * from.z) + (p * dest.z));
return qo;
}
【问题讨论】:
标签: c++ opengl 3d quaternions