博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DirectX11 XNA数学库之矩阵
阅读量:4088 次
发布时间:2019-05-25

本文共 4926 字,大约阅读时间需要 16 分钟。

XNA数学库之矩阵

1. XNA数学库之矩阵介绍
跟XNA向量一样为了使用SSE2优化指令,XNA矩阵XMMATRIX的实现使用了四个向量。

2. 矩阵类型

XMMATRIX的定义如下:

//Matrix type: Sixteen 32 bit floating point components aligned on a    //    16 byte boundary and mapped to four hardware vector registers#if (defined(_XM_X86_) || defined(_XM_X64_)) && defined(_XM_NO_INTRINSICS_)    typedef struct _XMMATRIX#else    typedef _DECLSPEC_ALIGN_16_ struct _XMMATRIX#endif{    union    {
// Use 4 XMVECTORs to represent the matrix for SIMD. XM VE CTOR r[4]; struct { FLOAT _11, _12, _13, _14; FLOAT _21, _22, _23, _24; FLOAT _31, _32, _33, _34; FLOAT _41, _42, _43, _44; }; FLOAT m[4][4]; };#ifdef __cplusplus _XMMATRIX() {}; // Initialize matrix by specifying 4 row vectors. _ XM MATRIX(FXMVECTOR R0, FXMVECTOR R1, FXMVECTOR R2, CXMVECTOR R3); // Initialize matrix by specifying the 16 elements. _XMMATRIX(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); // Pass array of sixteen floats to construct matrix. _XMMATRIX(CONST FLOAT *pArray); FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; } FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; } _XMMATRIX& operator= (CONST _XMMATRIX& M);#ifndef XM_NO_OPERATOR_OVERLOADS _XMMATRIX& operator*= (CONST _XMMATRIX& M); _XMMATRIX operator* (CONST _XMMATRIX& M) CONST;#endif // !XM_NO_OPERATOR_OVERLOADS#endif // __cplusplus} XMMATRIX;

除了使用上面不同的构造函数,你还可以使用:

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);

通样地,我们使用XMMATRIX来计算,使用XMFLOAT4X4来储存,XMFLOAT4X4的定义如下:

//4x4 Matrix: 32 bit floating point components    typedef struct _XMFLOAT4X4{    union    {        struct        {            FLOAT _11, _12, _13, _14;            FLOAT _21, _22, _23, _24;            FLOAT _31, _32, _33, _34;            FLOAT _41, _42, _43, _44;        };        FLOAT m[4][4];    };#ifdef __cplusplus    _        XM        FLOAT4X4() {};    _        XM        FLOAT4X4(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);    _XMFLOAT4X4(CONST FLOAT *pArray);    FLOAT operator() (UINT Row, UINT Column) CONST { return m[Row][Column]; }    FLOAT& operator() (UINT Row, UINT Column) { return m[Row][Column]; }    _XMFLOAT4X4& operator= (CONST _XMFLOAT4X4& Float4x4);#endif // __cplusplus} XMFLOAT4X4;

3. 矩阵函数

矩阵使用如下计算函数:

MMATRIX XMMatrixIdentity(); // Returns the identity matrix IBOOL XMMatrixIsIdentity( // Returns true if M is the identity matrix    CXMMATRIX M); // Input MXMMATRIX XMMatrixMultiply( // Returns the matrix product AB    CXMMATRIX A, // Input A    CXMMATRIX B); // Input BXMMATRIX XMMatrixTranspose( // Returns Mτ    CXMMATRIX M); // Input MXMVECTOR XMMatrixDeterminant( // Returns (det M, det M, det M, det M)    CXMMATRIX M); // Input MXMMATRIX XMMatrixInverse( // Returns M−1XMVECTOR* pDeterminant, // Input (det M, det M, det M, det M)    CXMMATRIX M); // Input M

XMMATRIX作为形参的时候,应该使用XMMATRIX来使得平台具有兼容性。

3. 矩阵变换函数

// Constructs a scaling matrix:XMMATRIX XMMatrixScaling(FLOAT ScaleX,FLOAT ScaleY,FLOAT ScaleZ); // Scaling factors// Constructs a scaling matrix from components in vector:XMMATRIX XMMatrixScalingFromVector(FXMVECTOR Scale); // Scaling factors (sx , sy , sz)// Constructs a x-axis rotation matrix : RxXMMATRIX XMMatrixRotationX(FLOAT Angle); // Clockwise angle θ to rotate// Constructs a y-axis rotation matrix : RyXMMATRIX XMMatrixRotationY(FLOAT Angle); // Clockwise angle θ to rotate// Constructs a z-axis rotation matrix : RzXMMATRIX XMMatrixRotationZ(FLOAT Angle); // Clockwise angle θ to rotate// Constructs an arbitrary axis rotation matrix : RnXMMATRIX XMMatrixRotationAxis(FXMVECTOR Axis,FLOAT Angle);//Axis n to rotate about//Clockwise angle θ to rotate Constructs a translation matrix:XMMATRIX XMMatrixTranslation(FLOAT OffsetX,FLOAT OffsetY,FLOAT OffsetZ); // Translation factors Constructs a translation matrix from components in a vector:XMMATRIX XMMatrixTranslationFromVector(FXMVECTOR Offset); // Translation factors (tx , ty ,tz)// Computes the vector-matrix product vM:XMVECTOR XMVector3Transform(FXMVECTOR V,CXMMATRIX M);//Input v//Input M// Computes the vector-matrix product vM where vw = 1 for transforming points:XMVECTOR XMVector3TransformCoord(FXMVECTOR V,CXMMATRIX M);//Input v//Input M// Computes the vector-matrix product vM where vw = 0 for transforming vectors:XMVECTOR XMVector3TransformNormal(FXMVECTOR V,CXMMATRIX M);//Input v//Input M

转载地址:http://xiyii.baihongyu.com/

你可能感兴趣的文章
【JAVA数据结构】双向链表
查看>>
【JAVA数据结构】先进先出队列
查看>>
String类的intern方法随笔
查看>>
【泛型】一个简易的对象间转换的工具类(DO转VO)
查看>>
1.随机函数,计算机运行的基石
查看>>
MouseEvent的e.stageX是Number型,可见as3作者的考虑
查看>>
移植Vim配色方案到Eclipse
查看>>
从超链接调用ActionScript
查看>>
谈谈加密和混淆吧[转]
查看>>
TCP的几个状态对于我们分析所起的作用SYN, FIN, ACK, PSH,
查看>>
网络游戏客户端的日志输出
查看>>
关于按钮的mouseOver和rollOver
查看>>
Netty框架
查看>>
Socket经验记录
查看>>
对RTMP视频流进行BitmapData.draw()出错的解决办法
查看>>
FMS 客户端带宽计算、带宽限制
查看>>
在线视频聊天(客服)系统开发那点事儿
查看>>
SecurityError Error 2148 SWF 不能访问本地资源
查看>>
Qt 静态编译后的exe太大, 可以这样压缩.
查看>>
3D游戏常用技巧Normal Mapping (法线贴图)原理解析——基础篇
查看>>