如何打印通过引用传递的glm :: vec3类型的矢量值? [英] How do I print vector values of type glm::vec3 that have been passed by reference?

查看:266
本文介绍了如何打印通过引用传递的glm :: vec3类型的矢量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的obj加载程序,它需要两个参数并将它们传递回输入变量。。但这是我第一次这样做,现在我不确定如何打印所述值。这是我测试加载程序是否正常工作的主要功能。我有两个类型为 glm :: vec3 的向量来保存顶点和法线数据。

I have a small obj loader and it takes two parameters and passes them back to the input variables.. however this is my first time doing this and i'm not sure how to print said values now. Here is my main function to test if the loader is working. I have two vectors of type glm::vec3 to hold the vertex and normal data.

std::vector<glm::vec3> vertices;
std::vector<glm::vec3> normals;    

int main() {
    bool test = loadOBJ("cube.obj", vertices, normals);
    for (int i = 0; i < vertices.size(); i++) {
       std::cout << vertices[i] << std::endl;   // problem line
    }

    return 0;   
}

上面注释的行是生成无用信息的原因。如果我这样保留程序并运行程序,我会冒出很多错误(未格式化,很长时间无法粘贴在这里),如果我添加引用运算符,则会得到如下输出:

The line commented above is what is generating useless info. If I leave it like that and run the program I get a bunch of errors spewed at me (too unformatted and long to paste here) and if I add the reference operator I get output like this:

0x711ea0
0x711eac
0x711eb8
0x711ec4    // etc

知道我在做什么错吗?

推荐答案

glm为此进行了扩展。添加 #include glm / ext.hpp glm / gtx / string_cast.hpp

glm has an extension for this. Add #include "glm/ext.hpp" or "glm/gtx/string_cast.hpp"

然后打印一个矢量,例如:

Then to print a vector for example:

glm::vec4 test;
std::cout<<glm::to_string(test)<<std::endl;

这篇关于如何打印通过引用传递的glm :: vec3类型的矢量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆