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 2 of 2

Thread: GLM - compile error with the division

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2013
    Posts
    17

    GLM - compile error with the division

    Hello forum,

    I am getting with the following code snippet:

    Code :
     
       glm::vec2 points[NumPoints];
     
       // Specifiy the vertices for a triangle
       glm::vec2 vertices[3] =
          {
    	 glm::vec2( -1.0, -1.0 ), glm::vec2( 0.0, 1.0 ), glm::vec2( 1.0, -1.0 )
          };
     
       // Select an arbitrary initial point inside of the triangle
       points[0] = glm::vec2( 0.25, 0.50 );
     
       // compute and store N-1 new points
       for ( int i = 1; i < NumPoints; ++i )
       {
          int j = rand() % 3;   // pick a vertex at random
     
          // Compute the point halfway between the selected vertex
          //   and the previous point
          //GETTING COMILATION ERROR IN THE FOLLOWING LINE
          points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
       }


    The error says there is matching operator.


    Any idea to get around the problem?



    Regards
    Sajjad

  2. #2
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362
    Take care when you are defining a floating point number as a constant. 0.0 is a double by default for the compiler (i.e 64 bit) . Add an f after each of your floating point number, so the compiler know that you want a float (32bits), and your code should compile. Because glm::vec2 contain 2 numbers of type float, not double. The overloaded / operator with double is not defined for glm::vec2. As an advice, try to avoid mixing floating point data type when you are doing floating point arithmetic.

    So replace at least
    Code :
     
    points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
    with
    Code :
     
    points[i] = ( points[i - 1] + vertices[j] ) / 2.0f;
    Last edited by trinitrotoluene; 02-04-2013 at 06:58 PM.

Posting Permissions

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