1
\$\begingroup\$

How do you divide two quaternions - say A and B - evenly by a scalar, to calculate the rotations between them to render a smoother rotation?

Effectively, say you want to smooth the rotations between A and B evenly by n. How do you calculate each quaternion value between A and B?

I have found that resorting to .eulerAngles leads to some wild gimbal locking, so I think the math needs to stay in quaternion space...

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

It sounds like you're describing Quaternion.Slerp. You can use this to generate quaternion at any particular fraction of the rotation between a start and an end quaternion:

IEnumerator<Quaternion> RotationSteps(Quaternion from, Quaternion to, int stepCount) {

    yield return from;

    for(int i = 1; i < stepCount; i++) {
        yield return Quaternion.Slerp(
                        from,
                        to,
                        i / (float)stepCount
                     );
    }

    yield return to;
}

Or you can compute the incremental rotation of a single step like so:

Quaternion travel = to * Quaternion.Inverse(from);

Quaternion step = Quaternion.Slerp(
                      Quaternion.identity,
                      travel,
                      1f / stepCount
                  );
\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .