print glm matrix types
This commit is contained in:
parent
3212dc15cf
commit
186d14cb48
|
@ -191,8 +191,8 @@ int SDL_RenderFillRect(SDL_Renderer*, const Box&);
|
|||
int lineColor(SDL_Renderer*, const Segment&, const Color&, std::uint8_t = 1);
|
||||
|
||||
/* Stream a text representation of a glm::vec of any type or dimension */
|
||||
template<int dimensions, typename Type>
|
||||
std::ostream& operator<<(std::ostream& out, const glm::vec<dimensions, Type, glm::defaultp>& vec)
|
||||
template<glm::length_t dimensions, typename Type, glm::qualifier qualifier>
|
||||
std::ostream& operator<<(std::ostream& out, const glm::vec<dimensions, Type, qualifier>& vec)
|
||||
{
|
||||
out << "{" << vec.x << ", " << vec.y;
|
||||
if constexpr (dimensions > 2)
|
||||
|
@ -207,6 +207,33 @@ std::ostream& operator<<(std::ostream& out, const glm::vec<dimensions, Type, glm
|
|||
return out;
|
||||
}
|
||||
|
||||
/* Add a GLM matrix to the stream, each row on its own line */
|
||||
template<glm::length_t columns, glm::length_t rows, typename Type, glm::qualifier qualifier>
|
||||
std::ostream& operator<<(std::ostream& out, const glm::mat<columns, rows, Type, qualifier>& mat)
|
||||
{
|
||||
/* get the transpose so we can iterate over the original matrix by row instead of column */
|
||||
glm::mat<rows, columns, Type, qualifier> transpose = glm::transpose(mat);
|
||||
out << std::endl << "{";
|
||||
/* print each column of the transpose, therefore printing each row of the original */
|
||||
for (std::size_t ii = 0; ii < transpose.length(); ii++)
|
||||
{
|
||||
if (ii > 0)
|
||||
{
|
||||
out << " ";
|
||||
}
|
||||
out << transpose[ii];
|
||||
if (ii == static_cast<std::size_t>(transpose.length() - 1))
|
||||
{
|
||||
out << "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
out << std::endl;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream&, const SDL_Color&);
|
||||
|
||||
/* Add the contents of a vector to the output stream */
|
||||
|
|
Loading…
Reference in New Issue