23

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 me.

What I'm trying to do is simply display the direction of a directional light using an arrow model.

The directional light's direction is a unit vector but models are rotated using quaternions.

So.. How do I rotate this model to match the direction of the light?

Or am I crazy and I can't really do that, given that the light has no position but the model does?

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Details for converting direction & up-vector to matrix: stackoverflow.com/questions/18558910/…
FYI, here's the correct answer: stackoverflow.com/a/1171995/126995
@soonts yes, you can do that. It just needs abit of explanation why its the same thing. You should add it as an answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.