Title: CO1301 Games Concepts Week 22 Cross Product
1CO1301 - Games ConceptsWeek 22Cross Product
the Model Matrix
2End of Semester
- Into the last three weeks of teaching (including
this week). - The last day of teaching is Friday, 25th April.
- Exam period begins 5th May. Look dates of exams
up on the University web site. - You do not have an exam in this module.
- I will teach for all of the remaining three weeks
and you are expected to attend both lectures and
practicals.
3Reading
- 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 1 "Vector Algebra"
4- Topic 1
- Reminder about vectors and dot product followed
by cross product
5Vectors
- A vector is a directed edge. In 3 dimensions a
vector has three components v(x, y, z)
For example the vector a (2, 2, 0)
6Length of a vector
- The length of a vector can be calculated from its
components.
7The normalised vector
- A normalised vector is a vector whose length is
1. - Also known as the unit vector.
- A vector can be normalised by dividing each of
its components by its length
8Dot product
- The dot product of two vectors v and w is
- The relationship between two vectors can be
calculated using the dot product. - The dot product of two vectors expresses the
angle between the vectors
9Cross Product
- The cross product (like the dot product) takes
its name from the symbol used a single cross
between two vectors.
- Pronounced "The cross product of v and w", or
just the shorthand of "the cross of v and w ". - The cross product takes two vectors and produces
a single vector as its result.
10Cross Product
Cross Product
Vector w
11Cross Product
- The cross product of two vectors is the vector
which are orthogonal (perpendicular or at
right-angles) to both of the vectors. - There will always be two vectors which are
orthogonal to our original two vectors one
sticking upwards and the other downwards
(relative to the original vectors). The cross
product is not commutative. The order of the
vectors produces the direction.
12Why is it important to you?
- What is interesting about the cross product?
- The cross product of two vectors v and w would
produce the local axis of rotation between the
two vectors.
- For example the cross product is used to
construct a LookAt() function and to implement
shader techniques such as normal mapping and
parallax mapping.
13- Topic 2
- Introducing Transformations
14Model Positioning Reminder
- A 3D model has its own local space
- three 3D vectors X,Y Z
- These are the local axes of the model.
- So when you move a model according to its local z
axis you are calling up the local axes of the
model in order to do the movement.
15Model Positioning
- These define the local rotation of the model,
e.g. rotating around its local y-axis, etc. - The following terms are less commonly used
nowadays but just in case you come across them - rotation around the local X is pitch (up and
down) - rotation around the local Y is yaw (side to side)
- rotation around the local Z is roll
163D Models in graphics
- 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 ). - The position of the model are its coordinates in
world space. The position is the location of its
local origin.
173D Models in graphics
- Every model has 4 items of data
- Vector representing the x-axis (relative to model
origin) - Vector representing the y-axis (relative to model
origin) - Vector representing the z-axis (relative to model
origin) - Vector containing the coordinates of the model
(relative to the world origin) - Why is it done in this way?
- Is it possible to do this any other way?
183D Models in graphics
- Each model within the TL-Engine has a floating
point array associated with it. The array is
actually a matrix and we'll talk about matrices
in a while. - It can be considered to be a 4 by 4 array
float matrix44
193D Models in graphics
- The first row of the array is the model's local
x-axis. - The second row of the array is the model's local
y-axis. - The third row of the array is the model's local
z-axis. - The final row of the array are the model's
coordinates.
- Ignore the final component of the vectors for now.
203D Models in graphics
float matrix44 0.2, 0.4, 0.1, 0 ,
1, 1, 1, 0 , 0.3, 0.3, 0.3 0 , 10,
3, 7, 1
21Transforming the model
- The matrix can be obtained using the GetMatrix()
method.
float matrix44 box-gtGetMatrix(
matrix00 )
- The fourth row of the array are the coordinates
of the model. The fourth row is accessed by
setting the first subscript of the array to 3.
matrix30 // Px matrix31 //
Py matrix32 // Pz
22Transforming the model
- So doing the following would set the coordinates
of the model to ( 4, 6, 3 )
matrix30 4.0f matrix31
6.0f matrix32 3.0f
- The matrix can be set using the SetMatrix()
method.
box-gtSetMatrix( matrix00 )
- And the box (in this case) would move to location
( 4, 6, 3 ).
23Scaling
- The axes also provide a scaling. The length of
the vectors X, Y Z can define the scaling in
that axis - 1.0 normal, 2.0 double size etc.
- Effectively scaling local space
- So if you obtain the matrix of the model and
multiply the components of the first row by 2,
you will double the size of the model along the
x-axis.
24Scaling
float matrix44 box-gtGetMatrix(
matrix00 ) matrix01
2.0f matrix02 2.0f matrix03
2.0f box-gtSetMatrix( matrix00 )
To scale the model in all of its axes, you would
need to multiply the second and third rows of the
array in the same way as the first, the effect of
this would be to reproduce the Scale() method.
25 26Matrices
- Singular matrix
- Plural matrices
- A matrix is a rectangular table of numbers.
- A matrix is composed of rows and columns.
27Why are matrices important to you?
- Matrices are an essential part of graphics.
- Transformations are carried out using matrices.
- Matrices are key element of linear algebra and
hence of computer graphics.
28Matrices
- 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.
29Matrix Sizes
1x3
2x3
3x1
4x4
3x2
30Matrix 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.
31Matrix Addition
32Matrix Addition
- Subtraction is identical to addition.
33Scalar multiplication
- Scalar multiplication is simply when each
component of a matrix is multiplied by a single
value, in effect scaling it.