行主序 与 列主序
row major 与 column major
glm
glm是列主序矩阵,
首先包含 #include <glm/gtc/type_ptr.hpp>以使用 glm::value_ptr 方法。
测试代码:
glm::vec3 Translation = { 5.0f, 0.0f, 0.0f };
auto matrix = glm::translate(glm::mat4(1.0f), Translation);
const float* val = glm::value_ptr(matrix);
for (int i = 0; i < 16; i++)
std::cout << val[i] << ", ";输出结果:
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5, 0, 0, 1,
DirectXMath
DirectXMath是行主序矩阵,
首先包含#include <DirectXMath.h> 它包含在 Windows sdk 中,vs安装一下即可。
测试代码:
auto matrix = DirectX::XMMatrixTranslationFromVector({5.0, 0.0, 0.0});
float* test = (float*)&matrix;
for (int i = 0; i < 16; i++)
std::cout << test[i] << ", ";输出结果:
1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5, 0, 0, 1,
hlsl
参考资料
Last updated