Directx11学习笔记【六】 基本的数学知识----矩阵篇

参考dx11龙书 Chapter2 matrix algebra(矩阵代数)

关于矩阵的一些基本概念定理(例如矩阵加减乘法,逆矩阵,伴随矩阵,转置矩阵等)可以参考*

https://zh.wikipedia.org/wiki/

XNA MATRICES

Matrix Types

在xna math中代表一个4*4的矩阵,我们使用XMMATRIX

当在类中存储数据时使用XMFLOAT4X4

用XMMatrixSet创建,原型为

XMMATRIX XMMatrixSet(FLOAT m00,FLOAT m01,FLOAT m02,FLOAT m03,

             FLOAT m10,FLOAT m11,FLOAT m12,FLOAT m13,

              FLOAT m20,FLOAT m21,FLOAT m22,FLOAT m23,

             FLOAT m30,FLOAT m31,FLOAT m32,FLOAT m33,

            );

下面是一些Matrix Functions

XMMATRIX XMMatrixIdentity();//单位矩阵

BOOL XMMatrixIsIdentity(CXMMATRIX M);//判断是否是单位矩阵

XMMATRIX XMMatrixMultiply(CXMMATRIX A,CXMMATRIX B);//矩阵相乘

XMMATRIX XMMatrixTranspose(CXMMATRIX M);//转置矩阵

XMVECTOR XMMatrixDeterminiant(CXMMATRIX M);//矩阵的行列式

XMMATRIX XMMatrixInverse(XMVECTOR *pDeteminiant,CXMMATRIX M);//逆矩阵

下面是dx11龙书给出的测试代码:

 #include <windows.h>
#include <xnamath.h>
#include <iostream>
using namespace std; ostream& operator<<(ostream &os, FXMVECTOR v)
{
XMFLOAT4 dest;
XMStoreFloat4(&dest, v);
os << "(" << dest.x << "," << dest.y << "," << dest.z << ")";
return os;
} ostream& operator<<(ostream &os, CXMMATRIX m)
{
for (int i = ; i < ; ++i)
{
for (int j = ; j < ; ++j)
{
os << m(i, j) << "\t";
}
os << endl;
}
return os;
} int main()
{
if (!XMVerifyCPUSupport())
{
cout << "xna math not supported" << endl;
return ;
}
XMMATRIX A(1.0f,0.0f,0.0f,0.0f,
0.0f,2.0f,0.0f,0.0f,
0.0f,0.0f,4.0f,0.0f,
1.0f,2.0f,3.0f,1.0f
);
XMMATRIX B = XMMatrixIdentity();
XMMATRIX C = A * B;
XMMATRIX D = XMMatrixTranspose(A);
XMVECTOR det = XMMatrixDeterminant(A);
XMMATRIX E = XMMatrixInverse(&det,A);
XMMATRIX F = A * E; cout << "A = " << endl << A << endl;
cout << "B = " << endl << B << endl;
cout << "C = A*B = " << endl << C << endl;
cout << "D = transpose(A) = " << endl << D << endl;
cout << "det = determinant(A) = " << det << endl << endl;
cout << "E = inverse(A) = " << endl << E << endl;
cout << "F = A*E = " << endl << F << endl; return ;
}

Directx11学习笔记【六】 基本的数学知识----矩阵篇

上一篇:typeahead.js 使用记录


下一篇:php常用几种设计模式的应用场景