SLERP #163
@ -39,6 +39,21 @@ void QuaternionOperations::inverse(const double* quaternion, double* inverseQuat
|
|||||||
VectorOperations<double>::mulScalar(inverseQuaternion, -1, inverseQuaternion, 3);
|
VectorOperations<double>::mulScalar(inverseQuaternion, -1, inverseQuaternion, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QuaternionOperations::slerp(const double q1[4], const double q2[4], const double weight,
|
||||||
|
double q[4]) {
|
||||||
|
double qD[4] = {0, 0, 0, 0}, left[4] = {0, 0, 0, 0}, right[4] = {0, 0, 0, 0};
|
||||||
|
|
||||||
|
multiply(q1, q2, qD);
|
||||||
|
double angle = getAngle(qD) / 2.;
|
||||||
|
|
||||||
|
VectorOperations<double>::mulScalar(q1, std::sin((1 - weight) * angle) / std::sin(angle), left,
|
||||||
|
4);
|
||||||
|
VectorOperations<double>::mulScalar(q1, std::sin(weight * angle) / std::sin(angle), right, 4);
|
||||||
|
VectorOperations<double>::add(left, right, q, 4);
|
||||||
|
|
||||||
|
normalize(q);
|
||||||
|
}
|
||||||
|
|
||||||
QuaternionOperations::QuaternionOperations() {}
|
QuaternionOperations::QuaternionOperations() {}
|
||||||
|
|
||||||
void QuaternionOperations::normalize(const double* quaternion, double* unitQuaternion) {
|
void QuaternionOperations::normalize(const double* quaternion, double* unitQuaternion) {
|
||||||
|
@ -23,6 +23,8 @@ class QuaternionOperations {
|
|||||||
|
|
||||||
static void inverse(const double *quaternion, double *inverseQuaternion);
|
static void inverse(const double *quaternion, double *inverseQuaternion);
|
||||||
|
|
||||||
|
static void slerp(const double q1[4], const double q2[4], const double weight, double q[4]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns angle in ]-Pi;Pi] or [0;Pi] if abs == true
|
* returns angle in ]-Pi;Pi] or [0;Pi] if abs == true
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user