Have Quaternion \$ Q\$ which is rotated on the \$X\$ axis 90 degrees.

\$Q\$ is now \$ (0.707106, 0.707106, 0, 0)\$.

I want to rotate \$Q\$ another 90 degrees by a different pivot \$P\$ so i will calculate \$ Q * -P * Q^{-1}\$, save the \$x,y,z\$ coordinates in \$ res(x,y,z)\$ and then \$ res = res + P\$. This should give me the offset between the new coordinates and the old ones, however in my case i get a big translation on the \$ Y \$ axis.

Example 1

Here i do both rotations around the same pivot, compared to first center then pivot.

Example 2

i do both rotations around the same point \$C(-0.5,0.5,0.5)\$ if it matters, for the second rotation i first rotate the pivot with the current rotation to get actual coordinates of the pivot.

I do all calculations in object space where the object center is at 0,0,0


Before i start a rotation i calculate where the pivot should be at the current rotation like this, it only happens when there are no active rotations, i choose to rotate by vertices[3]

state.currentPivot = state.rotation * vertices[3];

this is the part of the update function that gets executed during rotations

for (auto& rotationRule : v_rotationRules)
    if (deltaTime >= rotationRule.startTime && deltaTime <= rotationRule.endTime)
        state.rotation = glm::rotate(state.rotation, glm::radians(rotationRule.degrees), rotationRule.axis);

TranslationMatrix = glm::translate(glm::mat4(1.0f), state.rotatedPosition());

    ModelMatrix =
        TranslationMatrix *
        glm::mat4_cast(state.rotation) *
glm::vec3 ObjectState::rotatedPosition()
    return position + rotationOffSet;

void ObjectState::rotateAroundPivotWithQuat()
    glm::vec3 negp = - currentPivot;
    glm::vec3 res = rotation * negp;
    rotationOffSet = res + currentPivot;

When a rotation is over i add position += rotationOffSet, happens at the end of it, and make it equal to (0,0,0) again.

in the gifs, the first value of rotationOffSet has the high offset on y axis, as i checked in debugger.

  • \$\begingroup\$ Can you show us your code here? It's unclear whether some steps have been elided because you consider them too obvious to mention in the text description, or because you've actually forgotten to do those steps - something looking at your code could help us verify. \$\endgroup\$ – DMGregory May 20 '19 at 12:28
  • \$\begingroup\$ @DMGregory tried to add everything related \$\endgroup\$ – rakuens May 20 '19 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.