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

Thread: [GLM] Operator overload

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    17

    [GLM] Operator overload

    Hey guys.

    So i'm using GLM and I have this code:
    Code :
    vec3	vhalf = (vec_v+vec_l) / 2;
    But it does not compile because it says that no operator "/" matches the operators.

    I can get work-around it by doing this instead:
    Code :
    vec3	vhalf = (vec_v+vec_l);
    	vhalf /= 2;
    Which is ok, but not as much pleasant to program or read.

    Am I missing something?
    Why isn't this operator supported in GLM since it is perfectly doable in GLSL ?

    thx

  2. #2
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: [GLM] Operator overload

    Because it's not possible to do in C++ without explicitly define the operator for each type.

    The problem here is cast. You can do:
    vec3 vhalf = (vec_v+vec_l) / 2.0f;

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2011
    Posts
    17

    Re: [GLM] Operator overload

    yeah, it solved the problem

    funny how I actually tryed it with " (vec_v+vec_l) / 2.0 " and didn't work, forgot to put the 'f' after "2.0", silly...

    Thank you!!

  4. #4
    Intern Contributor
    Join Date
    Sep 2010
    Posts
    74

    Re: [GLM] Operator overload

    A minor thing, it is usually better to multiply by 0.5f than to divide by 2.0f. It is faster (though most compilers probably optimize the division into the multiplication), but more importantly multiplication is commutative. I have had bugs originating from that division isn't.

Posting Permissions

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