1 / 30

CO1301: Games Concepts

Explore the importance of matrices in graphics, learn about transformations, rendering 3D models, matrix algebra, model positioning, and more. Dive into matrix addition, scalar multiplication, and matrix multiplication concepts in this informative lecture.

ddina
Download Presentation

CO1301: Games Concepts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CO1301: Games Concepts Lecture 12 Matrices Dr Nick Mitchell (Room CM 226) email: npmitchell@uclan.ac.uk Material originally prepared by Gareth Bellaby

  2. Reading • Rabin, Introduction to Game Development: • 4.1: "Mathematical Concepts" • Van Verthe, Essential Mathematics for Games: • Chapter 2: "Linear Transformations and Matrices" • Chapter 3: "Affine Transformations". • Frank Luna, Introduction to 3D Game Programming with DirectX 9.0c: A Shader Approach • Chapter 2: "Matrix Algebra" • Wendy Stahler, Fundamentals of Math and Physcis for Games Programmers, Pearson, Prentice Hall, 2006.

  3. Model Positioning Reminder • Each model has three axes definied: x, y and z. • The axes of the model are local to the model. • The axes are relative to the origin of the model, • i.e. ( 0, 0, 0 ). • Each model also has a position. • The position is in world coordinates. • The position is the location of its local origin.

  4. 3D Models in graphics • Recorded as a 4x4 matrix. x-axis y-axis z-axis position

  5. Matrices • Singular: matrix • Plural: matrices • A matrix is a rectangular table of numbers. • A matrix is composed of rows and columns.

  6. Why are matrices important? • A console typically runs at 30 frames per second. A PC game may run at 60 frames per second. • You therefore only have something in the region of between 0.017 to 0.033 of a second to perform all of the operations you need to carry out for the game. This includes AI, game logic, physics and, of course, updating and rendering the scene. • Computer games need to be efficient. • Matrices are efficient.

  7. Why are matrices important? • Matrices are an essential part of graphics. • Transformations are carried out using matrices. • Matrices are a key element of linear algebra and hence of computer graphics. • A single matrix can express a complex transformation. • For example, a single matrix can rotate a model in all 3 axes simultaneously, whilst at the same time moving and scaling. • Matrices can be combined together. • The resulting matrix will perform all of the operations of the individual matrices but in one single mathematical operation.

  8. Rendering a model • How is a model rendered on the screen? • A model is made up of polygons. In practice these are triangles. • A triangle is stored using the coordinates of each of its 3 points - the vertices. • (e.g. look at an .x file for vertex lists). • The coordinates of the vertices are in local space- relative to the origin of the model. • Another way of saying this is that the coordinates of the vertices of the triangles are in model space. • The model is also rotated - along 3 different axis.

  9. Rendering a model • So... • Every vertex needs to be transformed into world space (3 rotations, a transformation, possibly scaling). • The screen is 2D... • The model needs projecting from 3D into 2D. • The camera has an imaginary screen somewhere in front of it. The model (now in world coordinates) is converted from 3D space into the 2D space of the screen. The model is projected onto this screen.

  10. Transformation • When you have a go with DirectX over summer you will see that matrices are used to perform this transformation: the world, view and projection matrices. • You will also see that the matrices can be combined into a single matrix that carries out all of the maths in one operation. • There are calls within DirectX to do all of the operations. • You need to understand the background. • You also need to understand the maths because some of the more interesting graphics requires other types of matrix operations.

  11. Matrices • Most important thing to remember with matrices is: • Row - Column • First manifestation of row-column is the size the matrix. You write the numbers of rows first and the number of columns second. • So a 2x3 matrix is composed of 2 rows and 3 columns.

  12. Matrix Sizes 1x3: • Rows by columns. 2x3: 3x1: 4x4: 3x2:

  13. Matrix Addition • Matrices can be summed together. • Addition is done component by component (the same way as vectors). • This only works if the matrices are the same size.

  14. Matrix Addition

  15. Matrix Addition • Subtraction is identical to addition.

  16. Scalar multiplication • Scalar multiplication is simply when each component of a matrix is multiplied by a single value, in effect scaling it.

  17. Matrix Multiplication • Matrices can be multiplied together. • Remember with matrices: • Row - Column • The second manifestation of row-column is matrix multiplication: when two matrices are multiplied together the rows of the first matrix are combined with the columns of the second matrix. • The number of columns in the first matrix has to be equal to the number of rows in the second.

  18. Step guide • Take a row of the first matrix. • Take a column from the second matrix. • The row is rotated clockwise so that it sits above the column. • The components of each will pair up, row component with column component (if this does not happen then the matrices cannot be multiplied). • Multiply the pairs together. • Sum all of the results. • The final result is one component of the new matrix.

  19. Matrix Multiplication example

  20. Matrix Multiplication • The location of the result in the new matrix is the position where the row and the column intersect.

  21. Matrix Multiplication example

  22. Matrix Multiplication • Anyone notice what operation is being performed here? • Multiplying a matrix by a compatible vector will perform a linear transformation on the vector. • Multiplying matrices together will produce a single matrix that performs their combined linear transformations. • It is the dot product of row i from A with column j from B.

  23. Matrix Multiplication • The size of the row must be equal to the size of the column in order to do matrix multiplication. • Or to put this the other way around. The number of columns in the first matrix has to be equal to the number of rows in the second. • Examine the dimensions of the matrices. The two inside numbers must be equal: • 2x3 . 3x1 • The size of the resulting matrix will be the two outside numbers. So the result of 2x3 . 3x1 will be a 2x1 matrix.

  24. Properties of Matrix Multiplication • (AB)C = A(BC) • (A + B)C = AC + BC • AB≠BA • This is important in graphics because matrices are multiplied and it is important to get the order right .

  25. Transpose • The transpose of a matrix simply interchanges the rows and the columns of the matrix. • It is important because vectors in graphics can be ordered by rows (DirectX) or columns (OpenGL and HLSL). • Represented by a superscript T. The transpose of matrix A is AT. • So a nxm matrix becomes an nxm matrix.

  26. The Identity Matrix • The identity matrix is a special matrix. The identity matrix is a square matrix that has zeros for all elements expect along the main diagonal. • Multiplying a matrix by the identity matrix leaves the matrix unchanged. • For example used as a starting point before additional operations are added to a matrix.

  27. Vectors • A matrix can have just one column or just one row. • A row or column matrix can be used to represent a vector. vector is: row matrix is: • DirectX uses row vectors (OpenGL uses column vectors).

  28. Transforming a Vector • If you multiply a row matrix by a 3x3 matrix, the result is another row matrix. • The 3x3 matrix therefore acts to transform the row matrix. • However, a 3x3 matrix can only produce some of the transformations required in 3D graphics. • So another component is added at the end to produce a row matrix with a length of 4. The transformation matrix now be a 4x4 matrix.

  29. Rotation using a matrix • Matrix multiplication is used to perform rotations. • Well start with Euler rotation. In year 3 you'll look at a faster alternative. • Euler is pronounced "oiler".

  30. Rotation using a matrix

More Related