   Questions about GLM (opengl math library)
  Hi dudes!I'm using GLM (http://glm.g-truc.net/) and have 2 questions:what is the correct way to cast a integer vector to a float?how can I multiply a floating vector with a number?This:vec2 v=vec2(0.8, 25.6);vec2 v1=0.5*v;Does not compile.Am I missing something?Thanks a lot.   
Quote:vec2 v=vec2(0.8, 25.6);vec2 v1=0.5*v;Does not compile.I'm not that familiar with the GLM API, but I'd be surprised if that syntax wasn't supported. Can you post the error message?By the way, you can most likely just write:vec2 v(0.8, 25.6);Rather than:vec2 v=vec2(0.8, 25.6);;Quote:Original post by jykQuote:vec2 v=vec2(0.8, 25.6);vec2 v1=0.5*v;Does not compile.I'm not that familiar with the GLM API, but I'd be surprised if that syntax wasn't supported. Can you post the error message?By the way, you can most likely just write:vec2 v(0.8, 25.6);Rather than:vec2 v=vec2(0.8, 25.6);Yes, I knew it, don't worry.Error message is:1>c:\source_code\level_loader\clevel.cpp(206) : error C2679: binary '*' : no operator found which takes a right-hand operand of type 'glm::core::type::vector::vec2' (or there is no acceptable conversion)Should I include anything?Thanks a lot.   ;  I took a quick look at the source code, and it looks like those operators are in vecx.hpp. I doubt you have to include that header explicitly to access those functions, but I'm not familiar enough with GLM's header structure to tell you what you do need to include.What is vec2? Is it a typedef for something? Maybe the problem is that the scalar type doesn't match the element type for the vector...   ;Quote:Original post by ricardo_ruiz_lopezError message is:1>c:\source_code\level_loader\clevel.cpp(206) : error C2679: binary '*' : no operator found which takes a right-hand operand of type 'glm::core::type::vector::vec2' (or there is no acceptable conversion)Try:  vec2 v1 = v*0.5;It is possible that there is no function that supports scalar multiplication on the left of a vector.;Quote:Original post by Dave EberlyQuote:Original post by ricardo_ruiz_lopezError message is:1>c:\source_code\level_loader\clevel.cpp(206) : error C2679: binary '*' : no operator found which takes a right-hand operand of type 'glm::core::type::vector::vec2' (or there is no acceptable conversion)Try:  vec2 v1 = v*0.5;It is possible that there is no function that supports scalar multiplication on the left of a vector.Nope. It does not work. I guess I have to include something. I cannot beleive multiply operator is not supported.   ;Quote:Nope. It does not work. I guess I have to include something. I cannot beleive multiply operator is not supported.If you haven't already, take a look at vecx.hpp. I don't have the code in front of me right now, but IIRC that's where these operators are declared.   ;  Here is the header.  The only operators I see defined are unary ops (v *= 3.0, for example).  It looks like there are some additional functions available in the glm::core::function namespace.   ;  The file type_vec2.inl contains implementations of    inline tvec2<T> operator* (tvec2<T> const & v, T const & s)    inline tvec2<T> operator* (T const & s, tvec2<T> const & v)These define vector*scalar and scalar*vector.  Is it possible that the GLM header file system is not automatically #including this *.inl file?;  I downloaded GLM and tried the following.#include "type_vec2.hpp"using namespace glm::core::type::vector;int main(){    vec2 val0(0.1,0.2);    return 0;}Lots of compiler errors.  I had to include glm.hpp.  I design my own header files so that if you include one by itself in a source file, that source file compiles.  In this manner, the user does not have to guess what else to #include or worry about order of #includes.This code compiles.#include "glm.hpp"#include "type_vec2.hpp"using namespace glm::core::type::vector;int main(){    vec2 val0(0.1,0.2);    return 0;}This code does not compile.#include "glm.hpp"#include "type_vec2.hpp"using namespace glm::core::type::vector;int main(){    vec2 val0(0.1,0.2), val1;    val1 = 0.5*val0;    return 0;}It fails with 60 errors of which the last one is the one you mention.  The other 59 are attempts to expand all the templates involving operator*.  The complaints were of the form "could not deduce template argument".  And the compiler tried expanding with various matrix and vector types.As it turns out, the problem is that the default "precision" appears to resolve to 'float' rather than 'double'.  That is, "vec2" is really a 2-tuple of 'float' values.  The signature of the multiply is operator*(tvec2<T> const & v, T const & s).  The compiler sees the 'double' 0.5 and cannot match it to a 'float', and it cannot find an operator* that takes a 2-tuple 'float' and a 'double' scalar.The following does compile.#include "glm.hpp"#include "type_vec2.hpp"using namespace glm::core::type::vector;int main(){    vec2 val0(0.1,0.2), val1;    val1 = 0.5f*val0;    return 0;}The compiler does allow the implicit conversion from the 'double' inputs of the constructor to 'float' inputs.If you want a default of 'double', I believe you have to #define GLM_PRECISION_HIGHP_FLOAT.I must say, code libraries should not be this difficult to use.  The overabundance of namespaces makes it very difficult to get simple code to compile.