Difference between the two quaternions

后端 未结 5 882
栀梦
栀梦 2020-12-28 16:59

Solved


I\'m making a 3D portal system in my engine (like Portal game). Each of the portals has its own orientation saved in a quaternion. To render the virtu

5条回答
  •  Happy的楠姐
    2020-12-28 17:34

    I solved my problem. As it turned out I don't need any difference between two rotations. Just multiply one rotation by rotation in 180 degrees, and then multiply by inverse of second rotation that way (using matrices):

    Matrix m1 = p1->getOrientation().toMatrix();
    Matrix m2 = p2->getOrientation().toMatrix();
    Matrix model = m1 * Matrix::rotation(180, Vector3(0,1,0)) * Matrix::inverse(m2);
    

    and translation calculating this way:

    Vector3 position = -p2->getPosition();
    position = model * position + p1->getPosition();
    model = Matrix::translation(position) * model;
    

提交回复
热议问题