PDA

View Full Version : computing glm::quat() from "forward" and "up"



john_connor
10-26-2017, 03:13 AM
hi,

i'm using glm for all the math, and i represent objects in "transform" objects:

struct Transformation
{
glm::vec3 Position;
glm::quat Rotation;

glm::mat4 Matrix() const { return glm::translate(Position) * glm::toMat4(Rotation); }
glm::mat4 View() const { return glm::inverse(Matrix()); }
};

from OpenAL (sound API), i get 2 directions for the "listener" (which is essentially the camera): forward and up dirction. the way i'm getting the "Transformation" is:

glm::quat al::listener::Orientation()
{
ALfloat orientation[6] = { 0 };
alGetListenerfv(AL_ORIENTATION, orientation);

/* get directions */
glm::vec3 forward(orientation[0], orientation[1], orientation[2]);
glm::vec3 up(orientation[3], orientation[4], orientation[5]);

/* get view matrix */
glm::mat4 view = glm::lookAt(glm::vec3(0, 0, 0), forward, up);

/* invert view matrix */
glm::mat4 transform = glm::inverse(view);

/* return rotation */
return glm::toQuat(transform);
}

i'm getting around the problem using matrices, but is there an easier / faster way to get the rotation somehow ??


thanks for any advice !!

technologist
11-04-2017, 10:10 AM
Hi, I was wondering if you could entertain a side question: why do you invert your matrix?

john_connor
11-05-2017, 04:44 AM
Hi, I was wondering if you could entertain a side question: why do you invert your matrix?

look here:
http://www.songho.ca/opengl/gl_camera.html