Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: computing glm::quat() from "forward" and "up"

  1. #1
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    435

    computing glm::quat() from "forward" and "up"

    hi,

    i'm using glm for all the math, and i represent objects in "transform" objects:
    Code :
    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:
    Code :
    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 !!

  2. #2
    Intern Contributor
    Join Date
    May 2017
    Posts
    64
    Hi, I was wondering if you could entertain a side question: why do you invert your matrix?

  3. #3
    Member Regular Contributor
    Join Date
    May 2016
    Posts
    435
    Quote Originally Posted by technologist View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •