Presentation is loading. Please wait.

Presentation is loading. Please wait.

CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.

Similar presentations


Presentation on theme: "CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby."— Presentation transcript:

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

2 Vectors  Rabin, Introduction to Game Development:  4.1: "Mathematical Concepts"  Van Verthe, Essential Mathematics for Games:  Chapter 1: "Vectors and Points"

3 Topics Reminder about vectors Model positioning The dot product

4  Topic 1:  Reminder about Vectors

5 Vectors (Revision)  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)

6 Length of a vector (Revision)  The length of a vector can be calculated from its components.

7 The normalised vector (Revision)  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:

8  Topic 2:  Model positioning

9 Model Positioning  A 3D model has its own local space:  three 3D vectors X,Y & Z  These define the local rotation of the model, e.g. rotating around its local y-axis, etc. It also defines what is meant by movement local to its own axis, e.g. MoveLocalZ() means move along the direction of the model's z-axis.

10 Model Positioning  In order to be able to use a model you also need its position. The position and rotation of a 3D model can be specified by defining its local space:  Position: a 3D vertex P  Rotation: three 3D vectors X,Y & Z Note the way in which the local axes of a model are described as vectors.

11 Model Positioning  Vectors 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  This is an example of why normalising vectors is important. Note: there are other ways to define model’s position In particular, rotation can be held differently

12  Topic 3: The dot product

13  The dot product gets its name from the symbol used: a single dot between two vectors. Pronounced "V dot W", or say "the dot product of V and W". The dot product takes two vectors and produces a single (numerical) result.

14 The dot product

15 Why is it important to you?  The reason why the dot product is so important is because of the following equation: Given any two vectors we can derive the angle between them. What happens if v and w are normalised?

16 If the vectors are normalised The length of a normalised vector is 1. The equation therefore simplifies as follows:

17 Example  This example also brings out the way in which vectors and coordinates are intimately related.  You had a monster which attacked if you moved close to it. It would be nice if you could sneak up behind the monster.  The monster is looking in a particular direction. The centre of its vision is pointing in a particular direction. Therefore this can be considered to be a vector, specifically a direction vector.  Actually this is known as the "facing vector". It is the direction of movement if the moved along its local z-axis in the positive direction.

18 Example Calculate the vector from the monster to the player, i.e. the location of the player minus the location of the monster. We now have two vectors. If we calculate the dot product of them this will tell us the angle between the vectors. In this manner we can determine whether the monster can currently see the player.

19 Some uses of the dot product  Showed the values of cos in earlier lecture  cos(0 o )=1  The dot product allows a quick test to see whether two vectors are pointing in the same direction.  cos(90 o )=0  So two vectors are perpendicular only if their dot products are 0.

20 Some uses of the dot product  Two vectors whose dot product yields 0 are known as orthogonal.  This is very useful in graphics.  You may have heard about “normal mapping”, e.g. in the context of graphics. The normal to a surface is a vector which is orthogonal to a surface.  Note: This is not the same as talking about a normalised vector!  More from Laurent next year…

21 Some uses of the dot product  The dot product of a vector with itself always produces a positive number. This number is equal to the square of the normalised vector.

22 Summary of the Argument  There is a relationship between angle of a triangle and the length of its edges.  The edge of a triangle can be considered to be a vector.  Two vectors connected together form a triangle.  The relationship between the vectors can be calculated using the dot product.  The dot product of two vectors expresses the angle between them.


Download ppt "CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby."

Similar presentations


Ads by Google