XNA中的Matrix结构
来源:互联网 发布:查看系统版本 linux 编辑:程序博客网 时间:2024/05/18 02:26
原址:http://blog.csdn.net/tanmengwen/article/details/7626244
The Matrix structure in XNA is a 4x4 matrix, which looks something like this:
- P1x P1y P1z w1
- P2x P2y P2z w2
- P3x P3y P3z w3
- vx vy vz w4
P1x P1y P1z w1 P2x P2y P2z w2 P3x P3y P3z w3 vx vy vz w4
While the 16 elements can really be any information you like, matrices are generally used for transformations (and most - but not all - of those transformations are "affine" transformations). In the matrix above, P1, P2, and P3 would be points, and v would be a vector. For an affine transformation,the 3x3 matrix of points (P1, P2, and P3) would indicate transformations like scaling and rotation, while the vector v would represent translation. In an affine transformation, w1, w2, and w3 would be 0, while w4 would be 1.
For example, a matrix representing doubling the scale of an object (uniform scaling of 2.0) and moving it 10 units along the Z axis would look like this:
- 2.0 0.0 0.0 0.0
- 0.0 2.0 0.0 0.0
- 0.0 0.0 2.0 0.0
- 0.0 0.0 10.0 1.0
2.0 0.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0 10.0 1.0
在XNA中使用的坐标系是右手坐标系
4X4矩阵在第一行的前三个值,即11,12,13值是在X轴上的分量,第二行前三个值即21,22,23为Y轴方向上的值,第三行前三个值31,32,33为Z轴方向上的值。
下面的代码,是一些属性,得到和设置矩阵在前后左右上下方向的分向量。
- public Vector3 Backward { get; set; }
- public Vector3 Down { get; set; }
- public Vector3 Forward { get; set; }
- public Vector3 Left { get; set; }
- public Vector3 Right { get; set; }
- public Vector3 Translation { get; set; }
- public Vector3 Up { get; set; }
public Vector3 Backward { get; set; } public Vector3 Down { get; set; } public Vector3 Forward { get; set; } public Vector3 Left { get; set; } public Vector3 Right { get; set; } public Vector3 Translation { get; set; } public Vector3 Up { get; set; }
Vector3.Forward=(0,0,-1) Vector3.Backward=(0,0,1)
Vector3.Left=(-1,0,0) Vector3.Right=(1,0,0)
Vector3.Up=(0,1,0) Vector3.Down=(0,-1,0)
旋转
Matrix myMatrix = Matrix.CreateFromAxisAngle(Vector3.Right,MathHelper .Pi/6);
上面代码的意思是围绕X正轴旋转30°,系统运行,让我们看一下得到的矩阵值,如下:
1
0
0
0
0
0.866
0.5
0
0
-0.5
0.866
0
0
0
0
1
下面是绕Y轴的例子:
Matrix myMatrix = Matrix.CreateFromAxisAngle(Vector3.Up,MathHelper .Pi/6);
0.866
0
-0.5
0
0.5
1
0
0
0.5
0
0.866
0
0
0
0
1
下面是绕Z轴的例子
Matrix myMatrix = Matrix.CreateFromAxisAngle(Vector3.Backward,MathHelper .Pi/6);
0.866
0.5
0
0
-0.5
0.866
0
0
0.5
0
1
0
0
0
0
1
缩放:
Matrix myMatrix = Matrix.CreateScale(2, 3, 4);
分别沿x,y,z轴扩大2,3,4倍。
2
0
0
0
0
3
0
0
0
0
4
0
0
0
0
1
平移
Matrix myMatrix = Matrix.CreateTranslation(2, 3, 4);
1
0
0
0
0
1
0
0
0
0
1
0
2
3
4
1
可见平移主要用到了第四组向量。
- XNA中的Matrix结构
- Matrix structure in XNA
- XNA中的显示
- XNA中的摄像机
- XNA中的RenderTarget
- XNA中的骨骼动画
- XNA中的骨骼动画
- XNA中的Alpha混合
- XNA在Silverlight 中的应用
- XNA数学库中的XMVECTOR
- Silverlight.XNA(C#)跨平台3D游戏研发手记:(三)蜂窝拓扑结构在SLG地图布局中的应用
- XNA
- XNA
- XNA学习笔记——SpriteBatch.Begin的Matrix参数
- XNA中的鼠标,键盘与操纵杆
- XNA中的拾取与碰撞检测
- XNA中的鼠标,键盘与操纵杆
- XNA中的拾取与碰撞检
- 30个创意出色的非常实用的jquery框架插件-(视觉大背景,瀑布流效果)
- 客户端链接RAC报错ORA-12545 的处理
- 【SQL Server学习笔记】索引调优、统计信息、查询调整、资源调控
- android使用外部数据库
- javascript匿名函数
- XNA中的Matrix结构
- 直接初始化和复制初始化有什么不同
- 安装oracle10g数据库出现错误oui-25031--configuration assistant失败
- 在Joomla!的组件里创建web service - 03: Joomla!自身的Component设计
- 软件测试流程进阶----两年软件测试总结
- 查找相同项的双螺旋匹配算法
- hdu 4334
- emacs js开发插件配置方法
- 微软危急: 20年转型未果 复兴路上最大敌人是自己