1 CO2301 - Games Development 1 Week 5 Deriving a "look at" function + Graph Theory Gareth Bellaby.

Slides:



Advertisements
Similar presentations
Decision Maths Networks Kruskals Algorithm Wiltshire Networks A Network is a weighted graph, which just means there is a number associated with each.
Advertisements

Lecture 15. Graph Algorithms
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
TECH Computer Science Graphs and Graph Traversals  // From Tree to Graph  // Many programs can be cast as problems on graph Definitions and Representations.
CSE 380 – Computer Game Programming Pathfinding AI
Introduction This chapter explores graphs and their applications in computer science This chapter explores graphs and their applications in computer science.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Arbitrary Rotations in 3D Lecture 18 Wed, Oct 8, 2003.
Learn to locate and graph points on the coordinate plane.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
3-D Geometry.
Chapter 9: Graphs Basic Concepts
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
x-axis quadrants origin y-axis OPENING ACTIVITY
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
EMSE 3123 Math and Science in Education
Chapter 2 Graph Algorithms.
Graph Theory Topics to be covered:
1 CO Games Development 1 Week 6 Introduction To Pathfinding + Crash and Turn + Breadth-first Search Gareth Bellaby.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
1 CO Games Concepts Week 20 Matrices continued Gareth Bellaby.
Representing and Using Graphs
POSITION & ORIENTATION ANALYSIS. This lecture continues the discussion on a body that cannot be treated as a single particle but as a combination of a.
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
Vertices and Edges Introduction to Graphs and Networks Mills College Spring 2012.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.
COSC 2007 Data Structures II Chapter 14 Graphs I.
Copyright © Ed2Net Learning Inc.1 Graphing in four Quadrants.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Math. A Coordinate Plane is a plane consisting of a set of two lines intersecting (crossing) each other at right angles. The horizontal line is the X-axis.
1 CO Games Development 1 Week 13 - Revision Lecture AI Revision Gareth Bellaby.
Rotation of Objects about Two or More Axes Module 8.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Composite 3D Transformations. Example of Composite 3D Transformations Try to transform the line segments P 1 P 2 and P 1 P 3 from their start position.
FROM PARTICLE TO RIGID BODY.
Computer Graphics Matrices
© 2013 Pearson Education, Inc. 12G Vectors in Space.
Week 4 Functions and Graphs. Objectives At the end of this session, you will be able to: Define and compute slope of a line. Write the point-slope equation.
Coordinate Plane.
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
1 CO Games Development 1 Week 4 Finite State Machines + Maths Gareth Bellaby.
The Coordinate Plane. Vocabulary Words Axes - two perpendicular number lines used for locating points Origin – the intersection of the two axes Y-axis.
1 Review Linear relationships. 2 Let’s investigate the relationship between x and y denoted by y = -2x – 2. We’ll complete the table and graph it. xy.
Source: CSE 214 – Computer Science II Graphs.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
5-1 The Coordinate Plane Introduction. Coordinate Graph.
CO1301: Games Concepts Dr Nick Mitchell (Room CM 226) Material originally prepared by Gareth Bellaby.
Unit 10 Transformations. Lesson 10.1 Dilations Lesson 10.1 Objectives Define transformation (G3.1.1) Differentiate between types of transformations (G3.1.2)
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
(CSC 102) Lecture 30 Discrete Structures. Graphs.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
1 CHAPTER 2C- Mohr’s Circle Dr. Zuhailawati Hussain EBB 334 Mechanical Metallurgy.
Vectors AP Physics C.
CO1301: Games ts 2015 Lecture 6 Vectors Dr Nick Mitchell (Room CM 224)
Basic Concepts Graphs For more notes and topics visit:
Graph Theory.
Graphs Chapter 13.
Chapter 9: Graphs Basic Concepts
Graphs.
Networks Kruskal’s Algorithm
CO Games Development 1 Week 8 Depth-first search, Combinatorial Explosion, Heuristics, Hill-Climbing Gareth Bellaby.
CO Games Concepts Week 12 Collision Detection
Chapter 9: Graphs Basic Concepts
GRAPHS.
Presentation transcript:

1 CO Games Development 1 Week 5 Deriving a "look at" function + Graph Theory Gareth Bellaby

2 Topics 1.Test for "to right", "to left" or "straight ahead". 2.Cross product 3.Deriving the local x-axis to test for "to right", "to left" or "straight ahead". 4.Using cross produce for collision detection 5.Derive a "look at"/point at function 6.Graph Theory

3 Topic 1 Test for "to right", "to left" or "straight ahead".

4 To right or left? Consider the situation where the rotation of the gun takes time. The gun needs to rotate in order to point at the target, rather than just being able to point directly at it. You need to calculate whether the target is to the left, to the right or straight ahead.

5 To right or left? You may have direct access to the local x-axis of the gun, e.g. in the TL-Engine. If this is case then this is similar to the first test. However, you employ the local x-axis in place of the z-axis. x is the gun's x-axis. w is the vector from the gun to the target. x w > 0 if the target is to the right x w = 0 if the target is straight ahead. x w < 0 if the target is to the left

6 To right or left? If your combine both of the tests then they can be used to identify which quadrant a target lies in relation to the guard (or gun, or whatever...) Note: we've also got the maths now for testing whether two vectors are orthogonal to one another, or parallel... this will turn out to be useful

7 Topic 2 Cross product

8 Cross Product The cross product takes its name from the symbol used: a single cross between two vectors. ●Pronounced "The cross product of v and w ", or "the cross of v and w ". ●The cross product takes two vectors and produces a single vector as its result.

9 Cross Product Vector v ● Vector w ● Cross Product

10 Cross 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.

11 Topic 3 Deriving the local x-axis to test for "to right", "to left" or "straight ahead".

12 Need to derive local x-axis Do not always have the local x-axis. The vectors can be many different things. One common instance is that one vector is the current velocity of an object and the second vector is the desired direction of travel. Also applicable to collision response, e.g. look at this talk: ppt Look at the Van Verth & Bishop.

13 How? You have the current velocity of the gun, or you have the current direction in which it is pointing. Call this the facing vector. How can you calculate the local the x-axis? ●Hint: the local x-axis will be orthogonal (at right angles) to the facing vector. ●Can use the cross product.

14 To right or left? v is the gun's facing vector (or can be velocity). u is the current up position, e.g. the world Y axis. d is the desired direction of travel, e.g. the vector pointing towards the target. Let x be the local x-axis. Then: ●Note that the order of the cross product is important. You will get a different result if calculate the cross product of v and u (the sign will be reversed). ●However, test will work if you don't normalise.

15 To right or left? ●Now we have the x-axis we can perform the second test as before. d ( u x v ) > 0 if the target is to the right d ( u x v ) = 0 if the target is straight ahead. d ( u x v ) < 0 if the target is to the left ● If the result is zero then the target is straight ahead. ● If the result is negative then the target is to the left. ● If the result is positive then the target is to the right.

16 Other ways ●As you can imagine, the axes can be derived in many different ways. ●The tests can be constructed in different ways as well. ●The following test has identical results to the one just given. ●Prove that this is the case.

17 Topic 4 Using cross product in collision detection

18 Axis-Aligned Box Check the position of the point against the minimum and maximum x, y and z values of the box. A straight forward calculation

19 Non-Axis-Aligned Box But what happens if the box isn't axis- aligned?

20 Non-Axis-Aligned Box Use the test for "in front or behind" and "to right or behind" (4 tests needed)

21 Topic 5 Derive a "look at"/point at function

22 Pointing at a target Targeting is important in computer games: for weapons, but also for chasing and tracking. You want to construct a "look-at" function. You have a gun and want to have the model to point at a target. It is easy to calculate the direction in which to point. Simply calculate the vector from the gun to the target.

23 Pointing at a target The vector from the gun to the target now becomes the new facing vector of the gun, i.e. its local z-axis. However, there is a problem. What is it? ●The other local axes are now wrong.

24 Pointing at a Target Need to recalculate the other axes. Use the cross product in the way already described to calculate the local x-axis. Then use the local x-axis to calculate the local y-axis. Note that all of the axes must be normalised.

25 Making the look-at matrix Let G be the position of the gun. Let T be the position of the target. Let z be the gun's facing vector: the local z-axis. Let u be the current up position, e.g. the world Y axis. Let x be the local x-axis. Let y be the local y-axis. Then:

26 Making the look-at matrix Calculate the facing vector (z) from position of the gun and the target. Use the cross product to derive the other axes. Derive the local x-axis (x) from the cross product of UP (the world Y axis) and z. Derive the local y-axis (y) from the cross product of z and x. All of the axes must be normalised.

27 Making the look-at matrix Derive the facing vector then normalise it. ●Derive the x-axis ●If the derived vector is orthogonal to the facing vector and orthogonal to the yAxis (the Up vector), then it must be the x-axis.

28 Making the look-at matrix Derive the local y-axis. ●Why are the vectors normalised? ●In this case the resulting vector is orthogonal to z and x and so must be the local y- axis.

29 Pointing at a Target ● // Calculate targeting matrix axes for gun ● // Get facing (z) vector from positions ● CVector3 vecZ = Normalise( Subtract( targetPosition, gunPosition ) ); ● // Use cross products to get other axes ● // Must normalise axes ● CVector3 vecX = Normalise( Cross( kYAxis, vecZ ) ); ● CVector3 vecY = Normalise( Cross( vecZ, vecX ) ); ● ● // Build targeting matrix from axes + position ● // Matrix constructor using four CVector3 variables ● // - one for each row/column ● // (see matrix header) ● // Build targeting matrix by row (axes + position) ● CMatrix4x4 gunMat; ● gunMat.MakeIdentity(); ● gunMat.SetRow( 0, vecX ); ● gunMat.SetRow( 1, vecY ); ● gunMat.SetRow( 2, vecZ ); ● gunMat.SetRow( 3, gunPosition ); ● // Set position of gun using matrix ● gun->SetMatrix( &gunMat.e00 );

30 Pointing at a Target The facing (z) vector has been derived. The front of the gun is pointing towards the target. If you were going to derive other movements it might not be UP that you need. The calculations have derived the other axes, but ignored their relative standing to the world. When we use this method to chase a target, you will see that the chasing body may turn upside down or do a roll. We've only considered the front of the gun, not it's other axes.

31 Topic 6 Graph Theory

32 Graph Theory A graph is composed of nodes, (alternatively called vertices) drawn as circles labelled The nodes are connected by edges (alternatively called arcs) drawn as lines between the nodes.

33 Edge orientation An edge may have no orientation. In this case the edge is undirected. Draw an line with no arrows.

34 Edge orientation An edge may have an orientation. In this case the edge is directed. Drawn using an arrow. The arrow head shows the orientation Graphs can be a mixture of undirected and directed. (We'll mostly be considering directed.) By convention a graph with directed edges is drawn pointing downwards

35 Repeating nodes A graph may connect back to itself: cyclic

36 Repeating nodes You will be more likely to see the diagram in this form, i.e. repeating nodes. One of the things I'll talk about in pathfinding is the removal of repetition.

37 Acyclic graph A graph may have the property that it never connects back to itself: acyclic. Once we remove repeating nodes this is the type of graph we'll end up with.

38 Graph Theory A weighted graph is one where each edge has some associated value.

39 Graph Theory If the edges are directed then the edges of the graph can be treated as ordered pairs, e.g. (a, b). The graph itself would be the set of ordered pairs. The edges of an undirected graph are unordered pairs, so the graph would be the set of adjoining edges. Considering the edges as pairs, and whether the pairs are ordered or ordered will be useful when you come to do the programming. (A,B) (A,C) (C,D) (C,E)

40 Examples Problems in graph theory. There are lots of different problems. The ones were mostly interested in are: Route problems. This is what we're interested in for path finding. specifically Graph searching problems or graph traversal Sub graphs. Graphs which are part of a graph.

41 Examples Locations on a map. Location turned into a graph Movement is from start to goal. Treat the edges as directed. Why we do we treat the edges as directed? Don't want to return to a previous location. The graph we build is acyclic for the same reason. In graph theory this category of problem is called "shortest path"

42 Example: pathfinding

43 Pathfinding as a graph Map is treated as a set of waypoint, which are then converted to nodes with directed edges.

44 Examples Graphs are also used to model conceptual problems, e.g. planning algorithms in which actions are represented by nodes and the problem converted into a graph More generally, decision making algorithms for our purposes are often expressed as graphs A finite state machine is a graph. We're also interested in efficient graphs, e.g. a minimum spanning tree (a subgraph that connects all of the nodes of a graph together. A minimum one would be the least costly tree).

45 Example: planning Goal Oriented Action Planning (GOAP). Used in games such as FEAR, Fallout 3, etc.

46 Planning as a graph Note that this graph forms a tree structure. Trees are a common data structure within computing