学习游戏编程(部分2)(数学)数学、部分、游戏

2023-09-08 00:08:18 作者:手腕上的伤

那么,它已经有几个月,因为我写的这个问题,自那时以来,我一直玩弄用原始C ++ D3D,的食人魔和Irrlicht的图形引擎和最近微软XNA。我已经建立了一些2D游戏(旧的东西,如俄罗斯方块,astreoids等大多是复制品),并提出了一些(非常)小步骤进入3D世界,在上面提到的技术。

So, it's been a few months since I wrote this question, since then I've toyed with "raw" C++ D3D, The Ogre and Irrlicht graphics engines and lately Microsoft XNA. I've built a few 2D games (mostly replicas of old stuff like tetris, astreoids, etc.) and made some (very) small steps into the 3D world in the above mentioned technologies.

我有很少或几乎没有任何其他的东西麻烦创建实际的游戏逻辑,抽象出对象的互动,让我插上不同形式的控制(电脑,播放器,通过网络,等等),做线程或I敢从我的日常工作​​习惯 - 这感觉非常自然的我。我搞砸周围很少有HLSL和粒子效果(非常非常基本的)。

I have little to no trouble creating the actual game logic, abstracting away object interactions to allow me to plug in different forms of control (computer, player, over network. etc.), doing threading or any of the other stuff I'm used to from my day to day work - which feels perfectly natural to me. I messed around very little with HLSL and particle effects (very very basic).

但是 3D数学涉及到矩阵和向量(和四元(?)的OGRE3D,是这些的真正的需要?)...真的打动了我,我可以按照示例(例如,学习XNA 3.0本书我O'Reilly出版,这是一个真棒书BTW买),我理解的为什么和如何的事情发生在这个例子中,但是当我尝试做自己的东西,我觉得我缺乏这种类型的数学的理解,要能的真正的得到它,让它通过自己的工作。

But 3D math involving Matrices and Vectors (and Quaternions(?) in Ogre3D, are these really needed?)... really gets me, I can follow examples (e.g. the Learning XNA 3.0 book I bought from O'Reilly, which is an awesome book btw) and I understand why and how something happens in the example, but when I try to do something myself I feel that I'm lacking the understanding of this type of math to be able to really get it and make it work by myself.

所以我在寻找资源,学习3D数学(主要)和一些着色器/粒子特效的书籍。我想preFER资源是教师,采取上述像一个医生的论文向量运算,这将是的办法的在我的头上慢慢来。理想的资源是什么,演示了这一切在D3D。

So I'm looking for resources on learning 3D math (mostly) and some Shader/Particle Effects books. I would prefer resources that are pedagogic and take it slow above something like a doctors thesis on vector math which will be way over my head. The ideal resource would be something that demonstrates it all in D3D.

推荐答案

好了,咋课程矩阵/矢量计算:

Ok, a quick course in Matrix/Vector calculation:

一个矩阵是数字下令在矩形网格的集合,如:

A matrix is a collection of numbers ordered in a rectangular grid like:

[ 0,  1,  2 ]
[ 2,  3,  5 ]
[ 2,  1,  3 ]
[ 0,  0,  1 ]

上述矩阵具有4行3列,因此是一个4×3矩阵。 的载体是用1行(行矢量)或1列(列向量)的矩阵。 普通数字称为标量与矩阵对比。

The above matrix has 4 rows and 3 columns and as such is a 4 x 3 matrix. A vector is a matrix with 1 row (a row vector) or 1 column (a column vector). Normal numbers are called scalars to contrast with matrices.

这也是通常使用大写字母的矩阵和小写字母标量。

It is also common to use capital letters for matrices and lowercase letters for scalars.

我们可以做基本的计算与矩阵,但也有一定的条件。

We can do basic calculation with matrices but there are some conditions.

添加

矩阵可以加入,如果它们具有相同的尺寸。因此2×2的矩阵可以被添加到一个2×2矩阵而不是一个3x5的矩阵

Matrices can be added if they have the same dimensions. So a 2x2 matrix can be added to a 2x2 matrix but not to a 3x5 matrix.

[ 1,  2 ] + [ 2,  5 ] = [ 3,  7 ]
[ 2,  4 ]   [ 0,  3 ]   [ 2,  7 ]

您看到,通过在每个数在每个小区被添加到数字上的其它基质相同的位置。

You see that by addition each number at each cell is added to the number on the same position in the other matrix.

矩阵乘法

矩阵可以被相乘,但是这是一个比较复杂。为了乘矩阵A与矩阵B,则需要乘以数字在每一行,如果矩阵A与矩阵B.这每列意味着如果你乘用acxd矩阵,B和C的AXB矩阵必须是平等的造成矩阵AXD:

Matrices can be multiplied, but this is a bit more complex. In order to multiply matrix A with matrix B, you need to multiply the numbers in each row if matrix A with each column in matrix B. This means that if you multiply an a x b matrix with a c x d matrix, b and c must be equal and the resulting matrix is a x d:

[1,2,3] x [4,6] = [1x4+2x2+3x2, 1x6+2x1+3x3 ] = [4+4+6,  6+2+9  ] = [14, 20]
[1,4,5]   [2,1]   [1x4+4x2+5x2, 1x6+4x1+5x3 ]   [4+8+10, 6+4+15 ]   [22, 25]
          [2,3]

正如你所看到的,与矩阵,A X B不同于宽x A.

As you can see, with matrixes, A x B differs from B x A.

矩阵标量乘法

您可以用乘以一个标量的矩阵。在这种情况下,每个小区被乘以该号码:

You can multiply a matrix with a scalar. In that case, each cell is multiplied with that number:

3 x [1,2] = [ 3, 6]
    [4,7]   [12,21]

反转矩阵 矩阵划分是不可能的,但你可以创建一个矩阵的逆使得A X A-INV是一个矩阵,与所有零的区别在于主对角线:

Inverting a matrix Matrix division is not possible, but you can create an inversion of a matrix such that A x A-inv is a matrix with all zero's except for that main diagonal:

[ 1, 0, 0 ]
[ 0, 1, 0 ]
[ 0, 0, 1 ]

反转的矩阵只能与方阵完成,这是一个复杂的作业,这并不neccesary有一个结果。

Inverting a matrix can only be done with square matrices and it is a complex job that does not neccesary have a result.

开始用矩阵A:

    [ 1, 2, 3 ]
A = [ 1, 3, 4 ]
    [ 2, 5, 1 ]

我们添加3个额外的列,并填写他们与单位矩阵:

We add 3 extra columns and fill them with the unit matrix:

[ 1, 2, 3, 1, 0, 0 ]
[ 1, 3, 4, 0, 1, 0 ]
[ 2, 5, 1, 0, 0, 1 ]

现在我们开始第一个列。我们需要减去彼此行的第一行,使得第一列包含除第一行只有零。 为了做到这一点,我们从第二从第三减去第一行一次和两次:

Now we start with the first column. We need to subtract the first row from each other row such that the first column contains only zeroes except for the first row. In order to do that we subtract the first row once from the second and twice from the third:

[ 1, 2, 3, 1, 0, 0 ]
[ 0, 1, 1,-1, 1, 0 ]
[ 0, 1,-5,-2, 0, 1 ]

现在我们与第二列(两次从第一行和一旦从第三)重复此

Now we repeat this with the second column (twice from the first row and once from the third)

[ 1, 0, 1, 3,-2, 0 ]
[ 0, 1, 1,-1, 1, 0 ]
[ 0, 0,-6,-1,-1, 1 ]

有关第三列,我们有一个小问题。枢轴号为-6,而不是1,但我们可以通过整个行与-1/6相乘解​​决这个问题:

For the third column, we have a slight problem. The pivot number is -6 and not 1. But we can solve this by multiplying the entire row with -1/6:

[ 1, 0, 1,   3,  -2,    0 ]
[ 0, 1, 1,  -1,   1,    0 ]
[ 0, 0, 1, 1/6, 1/6, -1/6 ]

和现在我们可以从第一和第二减去第三行:

And now we can subtract the third row from the first and the second:

[ 1, 0, 0, 17/6,-13/6,  1/6 ]
[ 0, 1, 0, -7/6,  5/6,  1/6 ]
[ 0, 0, 1,  1/6,  1/6, -1/6 ]

好了,现在我们有一个逆:

Ok now we have the inverse of A:

[ 17/6,-13/6,  1/6 ]
[ -7/6,  5/6,  1/6 ]
[  1/6,  1/6, -1/6 ]

我们可以这样写的:

      [ 17,-13,  1 ]
1/6 * [ -7,  5,  1 ]
      [  1,  1, -1 ]



    [ 1, 2, 3 ]   [ 17,-13,  1 ]                [ 6, 0, 0 ]    [ 1, 0, 0 ]
A = [ 1, 3, 4 ] x [ -7,  5,  1 ] x 1/6  = 1/6 x [ 0, 6, 0 ] =  [ 0, 1, 0 ]
    [ 2, 5, 1 ]   [  1,  1, -1 ]                [ 0, 0, 6 ]    [ 0, 0, 1 ]

希望这有助于一点。

Hope this helps a bit.

 
精彩推荐
图片推荐