Presentation is loading. Please wait.

Presentation is loading. Please wait.

CO1301: Games ts 2015 Lecture 6 Vectors Dr Nick Mitchell (Room CM 224)

Similar presentations


Presentation on theme: "CO1301: Games ts 2015 Lecture 6 Vectors Dr Nick Mitchell (Room CM 224)"— Presentation transcript:

1 CO1301: Games ts 2015 Lecture 6 Vectors Dr Nick Mitchell (Room CM 224)
Material originally prepared by Gareth Bellaby

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

3 Lecture Outline Maths Preliminaries Coordinates Vectors
Vector arithmetic Vector length The direction vector and scalars

4 Topic 1: Some Maths Preliminaries

5 Order of precedence Mathematical operations have an order of precedence. Multiplication and division have equal precedence. Multiplication and division are always carried out before addition and subtraction. ? ? ? ?

6 Right-angled triangles
Pythagoras’ Theorem With a right-angled triangle the length of the longest side (called the hypotenuse) is equal to the square root of the sum of the squares of the other two sides.

7 Right-angled triangles

8 Topic 2: Coordinates

9 Coordinates A coordinate represents a point in space.
A point in 2D is represented using coordinates (x, y) In 3D it is represented using coordinates (x, y, z) The convention is: use round brackets a comma separated list, e.g. ( 2, 4, 7 ) always in the sequence: x, y, z. Called Cartesian geometry after Rene Descartes.

10 Coordinates We use a 3D grid to identify points in space.
Can choose the direction to point Z. Use your hand to indicate the geometry. This gives the "handedness" of the geometry. In the TL-Engine we are using left-handed axes. Z Y X is thumb Y index finger Z middle finger X

11 Coordinates Y Z Z Y X X The origin of the grid is at ( 0, 0, 0 )

12 Topic 3: Vectors

13 Vectors We often need to identify a movement or direction in 3D - this can also be represented using values (x, y, z) and is called a vector. Vectors are more easily shown in 2D using where we only need (x, y) values.

14 Vector between two points
Calculated by subtracting one point from the other. Subtract: the x values to produce one new x; the y values to produce a new y; and then the z values to produce a new z. The vector V from P1(x1, y1) to P2(x2, y2) is: V( x2 - x1, y2 - y1) Sometimes written P1 P2 Note that P1 is subtracted from P2

15 Vectors The arrow of movement from P1 to P2 can be represented as the vector V(20,10). V( x2 - x1, y2 - y1) = (30, 30) - (10, 20) = (20, 10) The vector V from point P1(x1, y1) to P2(x2, y2) is ?

16 Vector between two points
Notice how the values in the vector are found by subtracting the source point coordinates from the destination point coordinates. This means that the direction of the vector is important: the vector in the reverse direction, from P2 to P1, is… (10, 20) - (30, 30) = (-20, -10) ?

17 Vectors 2D extends simply to 3D. The vector V from point P1(x1, y1, z1) to P2(x2, y2, z2) is V( x2 - x1, y2 - y1, z2 - z1) Points and vectors are represented in the same way. A vector can be directly applied to a point. Location and movement can all be considered to be the same thing. A point is represented by P(x, y, z) A vector is represented by V(x, y, z) A vector of force is represented in the same way e.g. the effect of wind.

18 Vectors The line between two points is the path you need to take to travel directly from one point to another. The vector is the same no matter what its coordinates are. At the origin this is obviously true. But you can also see this will be true wherever the points are: you can move the vector over the grid and it stays the same.

19 Vector direction Which point is subtracted from which is important.
The order gives us the direction of movement. P1(1, 1) to P2 (3, 3) =(3 - 1, 3 - 1) = (2, 2) P2(3, 3) to P1 (1, 1) = (1 - 3, 1 - 3) = (-2, -2)

20 Vector direction If you ever need a reminder about the order when calculating the vector between two points just think about the direction of the movement. Easiest to do this if you imagine one of the points being at the origin. From (0, 0, 0) to (2, 2, 0) = ( 2 - 0, 2 - 0, 0 - 0) = ( 2, 2, 0 ) Upwards and to the right From (2, 2, 0) to (0, 0, 0) = ( 0 - 2, 0 - 2, 0 - 0) = ( -2,- 2, 0 ) Downwards and to the left

21 Topic 4: Vector Arithmetic

22 Vector Addition We visualise vectors by drawing a line with an arrowhead at one end. Two vectors V and W are added by placing the beginning of W at the end of V.

23 Vector Addition V(1, 3) W(3, 1) = (4, 4) ?

24 Vector Subtraction ? Subtraction works in the same way as addition.
The direction in which the subtracted vector points is effectively reversed. V(1, 3) W(3, 1) = (-2, 2) ?

25 Vector Arithmetic The order of operations is irrelevant. V + W = W + V

26 Topic 5: Vector Length

27 Length of a vector If we have a vector V(x, y, z) then we can use Pythagoras’ Theorem to show that:

28 Length of a vector Easiest with a 2D example.
A vector makes a right-angled triangle. The shortest sides of the triangle are the x and y values. 3D is exactly the same - but with the addition of tee z axis.

29 Maths symbol for length
The length of a vector v(x, y, z) is given by:

30 Topic 6: The direction vector
and scalars

31 Direction of movement The direction between two points is only partly useful. The problem is that its size depends on the distance between the two points. Both vectors are pointing in the same direction, but the black vector is half the size of the red vector

32 Direction of movement As you know, the units we use within 3D graphics are arbitrary. Sometimes in the TL-Engine a distance of 0.1 is large, sometimes it is small. It all depends on the scale of the models. Direction should be independent of scale. The direction vector is a vector which is independent of scale. The direction vector has a length of 1. A vector whose length is 1 is said to be normalised.

33 The direction vector The direction vector is found by:
Calculating the length of the vector Dividing each component of the vector by its length For example, given a vector V( 1, 3, 6 ) length direction vector

34 The direction vector Here is a 2D example of the process: length

35 3D example Vector pointing straight forward: ( 0, 0, 7.5 )
length length direction vector direction vector

36 "Pointing at" or "Looking at"
Vectors can be used to represent a direction (in the sense of North or North-West). To do this we create a vector that ‘points’ in the direction we want, and has a length of 1 unit. We often need to find the direction vector that ‘points’ from one position to another. The process we use is: Get the vector between the two positions V(x, y, z) Find the length of this vector l (using pythagoras) The direction vector is VDir (x / l, y / l, z / l)

37 Maths for normalised vector
A normal is any vector whose length is 1 Represented with a ^ symbol: A vector is converted to a normal (normalised) by dividing the components by the length:

38 Scalar Direction vectors are always length 1.
They are always the unit length. In order to describe an actual movement you combine the direction vector with a scalar. The scalar is the distance to be moved. Imagine that you want to move something by a given distance in a particular direction. We multiply the direction vector by the distance we want to move. For example, move the normalised vector ( 2, 4, 5 ) by 12 units results in ( 24, 48, 60 )

39 Scalar A normalised vector can be seen as the direction of a vector
A vector can be broken up into normalised vector and length, e.g. Movement = Normalised vector * distance Velocity = Normalised vector * speed The scalar changes the magnitude of a vector. The root word is "scale". The operation of the scalar is to scale the vector. This also reminds us why normalised vectors are useful.


Download ppt "CO1301: Games ts 2015 Lecture 6 Vectors Dr Nick Mitchell (Room CM 224)"

Similar presentations


Ads by Google