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: glm::rotation syntax help

  1. #1
    Intern Newbie
    Join Date
    May 2017
    Posts
    36

    glm::rotation syntax help

    Trying to rotate x degrees around a given vector

    glm::vec3 myRotationAxis( 3, 6, 9);
    glm::rotate( 45, myRotationAxis );


    but am getting an error:

    .\src\main.cpp:128:34: error: no matching function for call to 'rotate(int, glm::vec3&)'
    glm::rotate( 45, myRotationAxis );

    Am I supposed to have a third parameter g.g. (model,45,myRotationAxis)?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,681
    glm::rotate is defined such that the angle and axis use the same base type; so assuming that glm::vec3 is a vector of 3 floats, then the angle must also be a float.

    What your compiler is telling you is that it's interpreting the angle as an int, and therefore that there is no matching overload.

    To fix, you need to tell the compiler that you want the angle to be interpreted as a float, either via a cast or by appending the "f" suffix; the latter should be preferable. So:

    glm::rotate( 45.0f, myRotationAxis );

  3. #3
    Intern Newbie
    Join Date
    May 2017
    Posts
    36

    before/after the same

    Quote Originally Posted by mhagain View Post
    glm::rotate is defined such that the angle and axis use the same base type; so assuming that glm::vec3 is a vector of 3 floats, then the angle must also be a float.

    What your compiler is telling you is that it's interpreting the angle as an int, and therefore that there is no matching overload.

    To fix, you need to tell the compiler that you want the angle to be interpreted as a float, either via a cast or by appending the "f" suffix; the latter should be preferable. So:

    glm::rotate( 45.0f, myRotationAxis );
    OK it worked at first but then something happened.
    I wrote a little program below to set the vector and to then print its contents. I already declared myRotationAxis elsewhere in the program.

    myRotationAxis = {3.0f,5.0f,7.0f};
    print_vector3(myRotationAxis);
    rotate(45.0f, myRotationAxis);
    print_vector3(myRotationAxis);

    output:
    vec3(3.000000, 5.000000, 7.000000)
    vec3(3.000000, 5.000000, 7.000000)

    myRotationAxis should be different from each other, but it seems the rotation isn't having an effect

    function call:

    glm::vec3 print_vector3(glm::vec3 test_vector3)
    {
    std::cout<<glm::to_string(test_vector3)<<std::endl ;
    return test_vector3;
    }

Tags for this Thread

Posting Permissions

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