免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 C/C++ memo
12下一页
最近访问板块 发新帖
查看: 3616 | 回复: 16
打印 上一主题 下一主题

[其他] memo [复制链接]

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-07 15:43 |只看该作者 |倒序浏览
Basic 3D Math: Matrices
Matrices are rectangular mathematical objects which have a number of rows and columns – think of it as a two-dimensional array. Take a look at the following:Above is a 3×4 Matrix (because it has 3 rows and 4 columns) – speak: 3 by 4 Matrix. Each element of the Matrix can be indexed by using the following notation: where i is the row and j the column: because the element at the 3rd rows and 2nd column has the value 10.Matrices are used in CG to represent a various number of different things like transformations and orientations.Part 1: Multiplying Matrices (Matrix Product)Matrix multiplication is not commutative, which means that the order of operation is relevant (as opposed to the multiplication of real numbers). In order to be able to multiply two matrices they must satisfy the rule that column of the first must match the rows of the second. Take a look at the following graphic which works as a simple reminder for the rules of matrix multiplication:But what’s the purpose of multiplying matrices? In 3D Programming you do Transforming a vertex with such a operation. Stop – how can i multiply a vector (which stores a vertex position) with a matrix? Vectors can be thought as Vectors with 1 Row and 4 Columns – and because multiplying a 1×4 Matrix with a 4×4 Matrix is a valid operation this works.In the first step, lets examine how to actually do the multiplication – formally this looks like:i = row index
j = column index
p = number of columns of the first matrix (or number of rows of the second one)Because a example often says more than thousand words, take a look at the following:We have two matrices: and . Multiplication of those two is possible because the number of columns of A matches the number of rows of B – the result is a 2×2 Matrix.Let’s perform the Calculation step by step.Step 1: Write down the calculation of every index for the resulting matrix
Step 2: Do the calculations
results in:Part 2: Creating Matrices for TransformationsAs mentioned above at the beginning of this document, matrices can be used to transform vectors. Its obvious that you need corresponding matrices which represent the transformation, so they are presented below – please note that they are for OpenGL only (The “why” is discussed at the end)Identity Matrix:The Identity matrix can be seen as the “reset” state matrix. If you multiply a vector with the Identity matrix you get the original vector. You initialise new matrices to the identity.Translation Matrix:X, Y and Z represent the amount you want to translate the vector on the axis.Scaling Matrix:X,Y and Z represent the amount of scaling on the corresponding axis.Rotation Matrix:There are four rotation matrices – one about each Axis (X,Y and Z) and one for rotating about an arbitrary axe. is the roation in radians.    The matrix used to rotate about an arbitrary axis is a little bit more complicated.Assumptations: Then the matrix looks like:The Vector (x,y,z) which represents the rotation axis must be normalizedMost of the time you don’t need to create those matrices by ourself because either the math library you are using provides them or you write your own.Part 3: Order of operation and combining transformationsThe order of multiplying multiple transformation matrices is cruical. In OpenGL you get the final transformation by reading your statement from left to right. Example:R is a rotation, T a translation matrix. The Vector V is first Translated and then rotated. Take a look at the pictures below to see the difference visually:In this Picture, the vertices of the Object are first multiplied by a rotation matrix (about Z) – which rotates the local object coordinates. After that a translation matrix (move along X)  is applied, so the object moves along the rotated X axis. The order of the multiplications are:As mentioned before, we read from right to left (Take Vector V, then Rotate, then Translate)This time we first multiply with a translation matrix (translate along X) and then apply a rotation matrix:Which means: Take Vector V, then translate, then rotate.Please note that the order only applies to OpenGL. In DirectX it’s from left to right – also the matrices are a little bit different in how they look like.Part 4: Going aheadMost OpenGL based 3D Libraries and Toolkits provide easy ways of creating the matrices mentioned above (i REALLY like Richard Wright’s Math3D Library which he uses in his Book OpenGL Superbible).If you want to dig deeper into the mathematics behind 3D Graphics, i highly recommend you the following two books:

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
2 [报告]
发表于 2013-05-07 15:58 |只看该作者
不明觉厉,越发崇拜妇科老人了

论坛徽章:
0
3 [报告]
发表于 2013-05-07 16:45 |只看该作者
3D矩阵。。好高深的样子。

论坛徽章:
5
技术图书徽章
日期:2013-08-17 07:26:49双子座
日期:2013-09-15 16:46:29双子座
日期:2013-09-25 08:17:09技术图书徽章
日期:2013-09-25 09:11:42天秤座
日期:2013-10-01 16:25:34
4 [报告]
发表于 2013-05-07 17:12 |只看该作者
这些都是最简单的基础知识, JB用都没有 ...

论坛徽章:
36
子鼠
日期:2013-08-28 22:23:29黄金圣斗士
日期:2015-12-01 11:37:51程序设计版块每日发帖之星
日期:2015-12-14 06:20:00CU十四周年纪念徽章
日期:2015-12-22 16:50:40IT运维版块每日发帖之星
日期:2016-01-25 06:20:0015-16赛季CBA联赛之深圳
日期:2016-01-27 10:31:172016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之福建
日期:2016-04-07 11:25:2215-16赛季CBA联赛之青岛
日期:2016-04-29 18:02:5915-16赛季CBA联赛之北控
日期:2016-06-20 17:38:50技术图书徽章
日期:2016-07-19 13:54:03程序设计版块每日发帖之星
日期:2016-08-21 06:20:00
5 [报告]
发表于 2013-05-07 17:27 |只看该作者
以前还研究过,现在都忘光了

游戏引擎里都写好了接口,我这种鸟用不上这些姿势啊

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
6 [报告]
发表于 2013-05-07 20:02 |只看该作者
回复 2# bruceteen


    我不想自已推导,所以做了个Memo,没想一上来就被你取笑。。
星星最近如何,转Linux了么?

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
7 [报告]
发表于 2013-05-08 09:15 |只看该作者
回复 6# folklore
俺不懂洋文,想嘲笑你也没办法呀^_^
俺还没转到Linux上,最近还是在混着
你最近在搞什么呀,越来越深奥了

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
8 [报告]
发表于 2013-05-08 12:45 |只看该作者
回复 7# bruceteen


    哪里深奥了。用高中的数学就能推出来吧。只是俺比较懒。。。。
现在在做一个CAD/CAM系统。各种苦B。

论坛徽章:
59
2015年亚洲杯之约旦
日期:2015-01-27 21:27:392015年亚洲杯之日本
日期:2015-02-06 22:09:41拜羊年徽章
日期:2015-03-03 16:15:432015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015元宵节徽章
日期:2015-03-06 15:50:392015年亚洲杯之阿联酋
日期:2015-03-19 17:39:302015年亚洲杯之中国
日期:2015-03-23 18:52:23巳蛇
日期:2014-12-14 22:44:03双子座
日期:2014-12-10 21:39:16处女座
日期:2014-12-02 08:03:17天蝎座
日期:2014-07-21 19:08:47
9 [报告]
发表于 2013-05-09 10:10 |只看该作者
  1. static void Matrix3dMultiple(double rt[4][4],double multiplicand[4][4],double multiplicate[4][4]){
  2.         double rs[4][4];
  3.        
  4.         for(int iY =0;iY<_countof(rs);iY++){
  5.                 for(int iX =0;iX<_countof(rs[0]);iX++){
  6.                         rs[iY][iX] =0.0L;
  7.                         for(int iAdd=0;iAdd <_countof(multiplicand[0]);iAdd++){
  8.                                 rs[iY][iX] +=multiplicand[iY][iAdd] *multiplicate[iAdd][iX];
  9.                         }
  10.                 }
  11.         }

  12.         memcpy(rt,rs,sizeof(rs));
  13. }// end function: Matrix3dMultiple
复制代码

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
10 [报告]
发表于 2013-05-09 10:59 |只看该作者
计算机领域太广了, 楼主竟然要和数学打交道.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP