简体   繁体   English

glm :: dot()不返回float / double值?

[英]glm::dot() doesn't return float/double value?

I am trying to use glm::dot to calculate the dot product of two glm::dvec3 我正在尝试使用glm::dot来计算两个glm::dvec3的点积

However, my compiler returns this error when I try to do this 但是,当我尝试执行此操作时,我的编译器将返回此错误

#include <glm/glm.hpp>

int main(int argc, char* argv[]){
    glm::dvec3 a = glm::dvec3(1f, 2f, 3f);
    glm::dvec3 b = glm::dvec3(4f, 5f, 6f);
    float weight = glm::dot(a, b)
}

ERROR: Type 'double' and 'glm::dvec3' are not compatible in the last line when I assign weight to the result of glm::dot 错误:当我将权重分配给glm :: dot的结果时,在最后一行Type 'double' and 'glm::dvec3' are not compatible

I am using (clion, cygwin, gcc) and glm 0.9.8 and c++ 11 我正在使用(clion,cygwin,gcc)和glm 0.9.8和c ++ 11

EDIT: Add more detailed error location and code context 编辑:添加更多详细的错误位置和代码上下文

Maybe there is a better solution, but this is working for me 也许有更好的解决方案,但这对我有用

glm::vec3 a;
glm::vec3 b;
glm::dot<3, float, glm::qualifier::highp>(a, b);

Since GLM has two methods dot 由于GLM有两种方法

template<typename T>
GLM_FUNC_QUALIFIER T dot(T x, T y)
{
    GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs");
    return x * y;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER T dot(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
{
    GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'dot' accepts only floating-point inputs");
    return detail::compute_dot<vec<L, T, Q>, T, detail::is_aligned<Q>::value>::call(x, y);
}

The compiler is assuming that T is vec3 and for that reason is using the first method 编译器假设T为vec3,因此使用第一种方法

Take a look to this post: 看一下这篇文章:

Templates C++ 模板C ++

In this specific case where the generic type T is used as a parameter for GetMax the compiler can find out automatically which data type has to instantiate without having to explicitly specify it within angle brackets (like we have done before specifying and ). 在将通用类型T用作GetMax的参数的特定情况下,编译器可以自动找出必须实例化的数据类型,而不必在尖括号中明确指定它(就像我们在指定and之前所做的那样)。 So we could have written instead: int i,j; 所以我们可以这样写:int i,j; GetMax (i,j); GetMax(i,j);

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM