Search code examples
c++openglglm-math

Opengl Precision Conversion Error compiling error E0415


Here I want to implement a simple OpenGL function which is similar to glulookat():

mat4 Transform::lookAt(vec3 eye, vec3 up) {
vec3 w = glm::normalize(eye);
vec3 u = glm::normalize(glm::cross(up, w));
vec3 v = glm::cross(w, u);
mat4 r = (
    u.x, u.y, u.z, 0,
    v.x, v.y, v.z, 0,
    w.x, w.y, w.z, 0,
    0, 0, 0, 1
    );

mat4 t = (
    1.0, 0.0, 0.0, -eye.x,
    0.0, 1.0, 0.0, -eye.y,
    0.0, 0.0, 1.0, -eye.z,
    0.0, 0.0, 0.0, 1.0
    );

mat4 result = glm::transpose(r)*glm::transpose(t);
return result;

}

VS2017 told me that:

Error (active)  E0415   no suitable constructor exists to convert from "double" to "glm::detail::tmat4x4<glm::core::type::precision::lowp_float>"

I know this problem might be caused by type conversion, however, After I modified all 0.0 to 0, similar problems occur again (no suitable XXX from "int" to XXX). I could not figure out how to solve it. Are there any suggestions?


Solution

  • There is a syntax error in your matrix declaration code, mat4 r = (...) is wrong. The correct syntax should be:

    mat4 r(...);
    

    (without = inbetween)