Skip to content

Commit 32b0663

Browse files
committed
reorganize the output of vector and matrix
1 parent 5597014 commit 32b0663

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

include/log_math.hpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
/**
3+
* @file matrix.hpp
4+
* @brief 矩阵
5+
* @author Zone.N (Zone.Niuzh@hotmail.com)
6+
* @version 1.0
7+
* @date 2022-09-07
8+
* @copyright MIT LICENSE
9+
* https://github.com/Simple-XX/SimpleRenderer
10+
* @par change log:
11+
* <table>
12+
* <tr><th>Date<th>Author<th>Description
13+
* <tr><td>2022-09-07<td>Zone.N<td>迁移到 doxygen
14+
* </table>
15+
*/
16+
17+
#ifndef SIMPLERENDER_SRC_INCLUDE_MATRIX_HPP_
18+
#define SIMPLERENDER_SRC_INCLUDE_MATRIX_HPP_
19+
20+
#define GLM_ENABLE_EXPERIMENTAL
21+
#include <glm/gtx/string_cast.hpp>
22+
23+
#include "log_system.h"
24+
25+
/**
26+
* spdlog 输出 Vector3f 实现
27+
*/
28+
template <>
29+
struct fmt::formatter<glm::vec3> : fmt::formatter<std::string> {
30+
auto format(const glm::vec3 &vector, fmt::format_context &ctx) const -> decltype(ctx.out()) {
31+
std::string vector_string = glm::to_string(vector);
32+
33+
// Format and output the string
34+
return fmt::format_to(ctx.out(), "\n{}", vector_string);
35+
}
36+
};
37+
38+
/**
39+
* spdlog 输出 Vector4f 实现
40+
*/
41+
template <>
42+
struct fmt::formatter<glm::vec4> : fmt::formatter<std::string> {
43+
auto format(const glm::vec4 &vector, fmt::format_context &ctx) const -> decltype(ctx.out()) {
44+
std::string vector_string = glm::to_string(vector);
45+
46+
// Format and output the string
47+
return fmt::format_to(ctx.out(), "\n{}", vector_string);
48+
}
49+
};
50+
51+
/**
52+
* spdlog 输出矩阵实现
53+
*/
54+
template <>
55+
struct fmt::formatter<glm::mat4> : fmt::formatter<std::string> {
56+
auto format(const glm::mat4 &matrix, fmt::format_context &ctx) const -> decltype(ctx.out()) {
57+
// Convert the glm::mat4 to a string using glm::to_string
58+
std::string matrix_str = glm::to_string(matrix);
59+
60+
// Format and output the string
61+
return fmt::format_to(ctx.out(), "\n{}", matrix_str);
62+
}
63+
};
64+
65+
#endif /* SIMPLERENDER_SRC_INCLUDE_MATRIX_HPP_ */

0 commit comments

Comments
 (0)