Skip to main content
Tweeted twitter.com/StackGameDev/status/1248944025681436672
added the matrix solution, but the question is about to create the quaternion straight out of a direction vector
Source Link
Avi
  • 188
  • 1
  • 1
  • 7

I have a unit vector (direction) which represent a rotation around Y axis,

and would like to turn this into a quaternion to represent the same rotation.

I use GLM library, but interested any library agnostic solution.

Should I pack the direction vector to a matrix then convert to quaternion? Is there a better way?

UPDATE: As I said the matrix solution works already, but there must be a shorter way, as i don't need all dimension only one (around Y):

glm::quat q = glm::conjugate(glm::toQuat(
    glm::lookAt(glm::vec3(from.getX(), from.getY(), from.getZ()),
                glm::vec3(from.getX(), from.getY(), from.getZ()) + direction,
                glm::vec3(0, 1, 0)
    )
));

I have a unit vector (direction) which represent a rotation around Y axis,

and would like to turn this into a quaternion to represent the same rotation.

I use GLM library, but interested any library agnostic solution.

Should I pack the direction vector to a matrix then convert to quaternion? Is there a better way?

I have a unit vector (direction) which represent a rotation around Y axis,

and would like to turn this into a quaternion to represent the same rotation.

I use GLM library, but interested any library agnostic solution.

Should I pack the direction vector to a matrix then convert to quaternion? Is there a better way?

UPDATE: As I said the matrix solution works already, but there must be a shorter way, as i don't need all dimension only one (around Y):

glm::quat q = glm::conjugate(glm::toQuat(
    glm::lookAt(glm::vec3(from.getX(), from.getY(), from.getZ()),
                glm::vec3(from.getX(), from.getY(), from.getZ()) + direction,
                glm::vec3(0, 1, 0)
    )
));
Source Link
Avi
  • 188
  • 1
  • 1
  • 7

Direction vector to quaternion

I have a unit vector (direction) which represent a rotation around Y axis,

and would like to turn this into a quaternion to represent the same rotation.

I use GLM library, but interested any library agnostic solution.

Should I pack the direction vector to a matrix then convert to quaternion? Is there a better way?