How do I print vector values of type glm::vec3 that have been passed by reference?

前端 未结 5 1617
星月不相逢
星月不相逢 2020-12-25 10:12

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 s

5条回答
  •  粉色の甜心
    2020-12-25 10:44

    glm::vec3 doesn't overload operator<< so you can't print the vector itself. What you can do, though, is print the members of the vector:

    std::cout << "{" 
              << vertices[i].x << " " << vertices[i].y << " " << vertices[i].z 
              << "}";
    

    Even better, if you use that a lot, you can overload operator<< yourself:

    std::ostream &operator<< (std::ostream &out, const glm::vec3 &vec) {
        out << "{" 
            << vec.x << " " << vec.y << " "<< vec.z 
            << "}";
    
        return out;
    }
    

    Then to print, just use:

    std::cout << vertices[i];
    

提交回复
热议问题