basics of 3d math in games
DESCRIPTION
Basics of 3D Math in Games. Matthew Christian. Overview. About Me Introduction to Linear Algebra Vectors Matrices Quaternions Links. About Me. Student Applied Mathematics and Computer Science: Software Development at UW-Stout Degree - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/1.jpg)
Matthew Christian
![Page 2: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/2.jpg)
About MeIntroduction to Linear AlgebraVectorsMatricesQuaternionsLinks
![Page 3: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/3.jpg)
StudentApplied Mathematics and Computer Science:
Software Development at UW-StoutDegree
Associates Degree in Computer Programming from Northcentral Technical College
GamerBeaten over 140 games (Yes I have a list)Independent Game Developer (spare time) for
5 yearsXNA developer for around a year and a half
![Page 4: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/4.jpg)
DefinitionThe part of algebra that deals with the theory
of linear equations and linear transformationsIn which the specific properties of vector
spaces are studied (including matrices)
This is NOT about ‘Linear Algebra’, it’s about the gaming version of ‘Linear Algebra’
![Page 5: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/5.jpg)
DefinitionsA variable quantity that can be resolved into
componentsA straight line segment whose length is
magnitude and whose orientation in space is direction
Vectors are simple row-based data structuresIn XNA:
Microsoft.XNA.FrameworkVector2, Vector3, Vector4public Vector2 ( float x, float y );
![Page 6: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/6.jpg)
Let P be a point at (2,2)
Then the vector p can be described as:
p = [2, 2]
Ex: [2,1] , [1,3]
![Page 7: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/7.jpg)
Vector AdditionAdd terms in similar positions
Vector “Subtraction”Remember, vectors represent directionsHow to subtract direction? Add negative
directionScalar-Vector Multiplication
Scaling a Vector up or down is easy, multiply each element by the scalar
Similar for Division (multiply by scalar fraction)Vector Matrix Multiplication
See later
![Page 8: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/8.jpg)
Dot ProductHelps determine the angle between 2 vectors
Cross ProductCreates another vector
perpendicular to the other two vectors (normal) (3D)
NormalizingMagnitude (length)
![Page 9: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/9.jpg)
Storing values (positions)Directions (move direction, collision
direction)
Demo(s)Simple VectorsVector Collision
![Page 10: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/10.jpg)
DefinitionA rectangular array of quantities… set out by
rows and columns, treated as a single element and manipulated accordingly…
For us programmers,Multi-dimensional arrays
A column is a 3x3 matrix if it has 3 rows and 3 columnsNxm matrix is a matrix with n rows and m
columns
![Page 11: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/11.jpg)
Square MatrixN-rows, N-columns
Main DiagonalRuns from upper left corner down (includes non-
square matrices)Diagonal Matrix
Matrix where all entries outside of the main diagonal are zero (main diagonal entries can be zero)
Identity MatrixThe matrix equivalent of multiplying by 1; 1’s
across the main diagonal with zero’s elsewhere (nxn sized)
![Page 12: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/12.jpg)
3D Rendering is possible BECAUSE of matrices
ModelViewProjection MatrixModel Matrix – Matrix describing the
position/rotation/scale of your objectOrder is important (multiply in order of operations)
View Matrix – Camera position, target, up direction (orientation)
Projection Matrix – View frustum ‘squished’ (your monitor doesn’t display ‘3D’)
![Page 13: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/13.jpg)
Math DemosTransformations!
In XNAMicrosoft.XNA.FrameworkMatrix4x4 matrix (M11 – M44)
DemosMatrixTransformationsCamera Demo (from Tutorials)
![Page 14: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/14.jpg)
Quaternions are compact descriptions of rotations…
Quaternions DON’T Prevent Gimbal LockMatrices use Euler numbers to calculate
rotations which ‘cancels’ a directionAfter calculating, you can only rotate on the Z-
Axis
In all honesty, I’m still researching it!
![Page 15: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/15.jpg)
(X, Y, Z, W)(X, Y, Z) is the axis to do rotations about(W) is the amount to rotate about that axis
Arbitrary AxisNot global axis
![Page 16: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/16.jpg)
DemoQuaternion Camera
![Page 17: Basics of 3D Math in Games](https://reader035.vdocuments.us/reader035/viewer/2022062304/568134ba550346895d9bda45/html5/thumbnails/17.jpg)
http://www.insidegamer.org/XnaTutorials.aspxMy tutorials (specifically Tutorial 4)
http://www.ziggyware.com/readarticle.php?article_id=54Specifically about Vectors in XNA
http://hyperphysics.phy-astr.gsu.edu/hbase/vect.htmlSome Vector operations
http://geekswithblogs.net/CodeBlogMy (seldom updated) Blog