Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
glm::vec3精度C++; 我用C++编写了一个碰撞检测系统,使用了 GLM库。_C++_Opengl_Glm Math - Fatal编程技术网

glm::vec3精度C++; 我用C++编写了一个碰撞检测系统,使用了 GLM库。

glm::vec3精度C++; 我用C++编写了一个碰撞检测系统,使用了 GLM库。,c++,opengl,glm-math,C++,Opengl,Glm Math,我有一个定义为std::vector vertices的顶点数组,还有一个计算定义为 GLfloat AssetInstance::maxX() { GLfloat max = vertices.at(0).x; for(glm::vec3 vertex : vertices) if(vertex.x > max) max = vertex.x; return max; } 但如果我运行以下代码: std::vector<glm::vec

我有一个定义为
std::vector vertices
的顶点数组,还有一个计算定义为

GLfloat AssetInstance::maxX()
{
    GLfloat max = vertices.at(0).x;

    for(glm::vec3 vertex : vertices)
        if(vertex.x > max) max = vertex.x;

    return max;
}
但如果我运行以下代码:

std::vector<glm::vec3> testVector;
testVector.push_back(glm::vec3(3.0500346, 1.0, 1.0));
testVector.push_back(glm::vec3(3.0500344, 2.0, 2.0));
testVector.push_back(glm::vec3(3.0500343, 3.0, 3.0));

std::cout << maxX(testVector) << std::endl;
std::vector testVector;
testVector.push_back(glm::vec3(3.0500346,1.0,1.0));
testVector.push_back(glm::vec3(3.0500344,2.0,2.0));
testVector.push_back(glm::vec3(3.0500343,3.0,3.0));

std::cout不,它们是单精度的
float
可以插入VBO,顺便说一句,
GLFoat
也是如此


可能你仍然得到了正确的索引,即使不是所有的数字都被打印出来。

不,它们是单精度的
float
可以插入VBO,顺便说一句,
GLFoat

这可能是因为即使不会打印所有数字,您仍能获得正确的索引。

试试看。默认情况下是6,这是您得到的

#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>
int main()
{
    std::cout << "default precision (6): " << 3.0500346 << '\n';
    std::cout << "std::precision(10):    " << std::setprecision(10) << 3.0500346 << '\n';

    return 0;
}
另一方面,您返回的是一个GLFloat,它是一个float,而不是一个double,所以无论glm使用什么,您都将它转换为一个float。因此,最终,调用maxX可以提供浮点精度,而不是双精度

注意:看这些文档,似乎有一种dvec类型,这让我怀疑vec默认使用double。

试试看。默认情况下是6,这是您得到的

#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>
int main()
{
    std::cout << "default precision (6): " << 3.0500346 << '\n';
    std::cout << "std::precision(10):    " << std::setprecision(10) << 3.0500346 << '\n';

    return 0;
}
另一方面,您返回的是一个GLFloat,它是一个float,而不是一个double,所以无论glm使用什么,您都将它转换为一个float。因此,最终,调用maxX可以提供浮点精度,而不是双精度

注意:看这些文档,似乎有一种dvec类型,这让我怀疑vec默认使用double