码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-03-03 22:54:19      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

参考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龙书给出的测试代码:

 1 #include <windows.h>
 2 #include <xnamath.h>
 3 #include <iostream>
 4 using namespace std;
 5 
 6 ostream& operator<<(ostream &os, FXMVECTOR v)
 7 {
 8     XMFLOAT4 dest;
 9     XMStoreFloat4(&dest, v);
10     os << "(" << dest.x << "," << dest.y << "," << dest.z << ")";
11     return os;
12 }
13 
14 ostream& operator<<(ostream &os, CXMMATRIX m)
15 {
16     for (int i = 0; i < 4; ++i)
17     {
18         for (int j = 0; j < 4; ++j)
19         {
20             os << m(i, j) << "\t";
21         }
22         os << endl;
23     }
24     return os;
25 }
26 
27 int main()
28 {
29     if (!XMVerifyCPUSupport())
30     {
31         cout << "xna math not supported" << endl;
32         return 0;
33     }
34     XMMATRIX A(1.0f,0.0f,0.0f,0.0f,
35                0.0f,2.0f,0.0f,0.0f,
36                0.0f,0.0f,4.0f,0.0f,
37                1.0f,2.0f,3.0f,1.0f
38         );
39     XMMATRIX B = XMMatrixIdentity();
40     XMMATRIX C = A * B;
41     XMMATRIX D = XMMatrixTranspose(A);
42     XMVECTOR det = XMMatrixDeterminant(A);
43     XMMATRIX E = XMMatrixInverse(&det,A);
44     XMMATRIX F = A * E;
45 
46     cout << "A = " << endl << A << endl;
47     cout << "B = " << endl << B << endl;
48     cout << "C = A*B = " << endl << C << endl;
49     cout << "D = transpose(A) = " << endl << D << endl;
50     cout << "det = determinant(A) = " << det << endl << endl;
51     cout << "E = inverse(A) = " << endl << E << endl;
52     cout << "F = A*E = " << endl << F << endl;
53 
54     return 0;
55 }

技术分享

 

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

标签:

原文地址:http://www.cnblogs.com/zhangbaochong/p/5240358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!