SLERP for antiparallel Quaternions #165
@ -51,15 +51,17 @@ void QuaternionOperations::slerp(const double q1[4], const double q2[4], const d
|
|||||||
multiply(q1s, q2I, qD);
|
multiply(q1s, q2I, qD);
|
||||||
angle = std::acos(qD[3]);
|
angle = std::acos(qD[3]);
|
||||||
|
|
||||||
|
if (std::cos(angle) < 0.0) {
|
||||||
|
// we need to invert one quaternion
|
||||||
|
VectorOperations<double>::mulScalar(q1s, -1, q1s, 4);
|
||||||
|
multiply(q1s, q2I, qD);
|
||||||
|
angle = std::acos(qD[3]);
|
||||||
|
}
|
||||||
|
|
||||||
if (std::sin(angle) == 0.0) {
|
if (std::sin(angle) == 0.0) {
|
||||||
// nothing to calculate here
|
// nothing to calculate here
|
||||||
std::memcpy(q, q1s, 4 * sizeof(double));
|
std::memcpy(q, q1s, 4 * sizeof(double));
|
||||||
return;
|
return;
|
||||||
} else if (std::cos(angle) < 0.0) {
|
|
||||||
// we need to invert one quaternione
|
|
||||||
VectorOperations<double>::mulScalar(q1s, -1, q1s, 4);
|
|
||||||
multiply(q1s, q2I, qD);
|
|
||||||
angle = std::acos(qD[3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorOperations<double>::mulScalar(q1s, std::sin((1 - weight) * angle) / std::sin(angle), left,
|
VectorOperations<double>::mulScalar(q1s, std::sin((1 - weight) * angle) / std::sin(angle), left,
|
||||||
|
Loading…
Reference in New Issue
Block a user