3Д БУМ

3Д принтеры и всё что с ними связано

Addition and Subtraction

Just like regular numbers, matrices can be added and subtracted. Matrix addition and subtraction are not used much in graphics pro­gramming, but that does not mean they cannot be used in other parts of your game. For instance, if you were building a strategy game, you could use a matrix to represent all of the remaining hitpoints of a group of units. You could add and subtract other matrices to or from this matrix to modify all of your unit’s hitpoints at once, rather than messing with each unit individually. Given two matrixes, A and B, you simply take each element from A and add it to the corresponding element in B. The resulting value goes in the same element in the resultant matrix, called C. For instance, if An is 5 and Bn is 9, Cn would be 14. If we were subtracting A and B, then Cn would be negative 4.

Going back to the strategy game example, if A11 represented the hitpoints of “unit1” and Bn represented the number of hitpoints when the unit passed through a certain area on the screen, Cn would store the final number of hitpoints for “unit1”. You could then run through the matrix and check for negative values, which would mean the unit is dead or disabled. Matrix addition is associative. This means, given three or more matrices, you can start by adding whichever two you like, without changing the final result. (A + B) + C = A + (B + C). It is also commutative, meaning you can add and subtract matrices in any order without changing the result. A + B = B + A. An illustration of matrix addition is shown in Figure 1.4.

~3

5

o”

~1

4

7~

"3+1

5+4

0+7~

~ 4

9

7~

4

4

8

+

3

4

9

=

4+3

4+4

8+9

=

7

8

17

9

6

1

0

3

2

9+0

6+3

1+2

9

9

3

Figure 1.4 An example of matrix addition using 3×3 matrices. Notice how each element of the first matrix is added to the corresponding element of the second matrix and the result is stored in the corresponding element of the final matrix.

Для любых предложений по сайту: [email protected]