Converting a direction vector to a quaternion rotation

前端 未结 1 757
甜味超标
甜味超标 2021-02-07 10:55

I can find a ton of questions about turning a quaternion into a direction vector but none for the other way around which makes me think I\'m doing something wrong, but bear with

1条回答
  •  一生所求
    2021-02-07 11:16

    A direction vector is not a defined rotation, it still has an infinite number of possible solutions. See there is no information for how to rotate around the axis. Two, vectors is possible as is a vector and a rotation (with a meaningful center) and in fact a fully defined matrix.

    Because in your case the rotation is rather meaningless, just use the up vector for reference (that is unless your light is shining top down or vice-versa then you need another reference).

    So take the cross product of your direction vector D and up vector U for the side vector S then cross D and S for a new Un. Then use D, Un, S as rows (or columns depending on how your calculation rule is set up) as a matrix. Matrix to quaternion is well known math.

    0 讨论(0)
提交回复
热议问题