some cool tricks. we can consider the screen as high school graph paper. each sprite or object is...

38
Mathematics Some Cool Tricks

Upload: alvin-jefferson

Post on 20-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

MathematicsSome Cool Tricks

Page 2: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Graphs

We can consider the screen as high school graph paper.

Each sprite or object is located somewhere in the coordinate system.

Page 3: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Our Screen

Remember our screen is not like the school mathematical graph paper! The origin is at the top-left!

That means the bottom of our object is at a higher y position than the top!

Page 4: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Translation

Moving things around is called translation.

Usually we translate our object to the origin before we perform rotation and scaling.

Page 5: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Translation

Move every point in one object to another location.

Page 6: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Rotation

For rotation, lets visit the Siggraph web page: https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm, accessed August 2014.

Page 7: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Pythagoras

We use Pythagoras to find the distance between two points.

Page 8: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Cartesian and Polar Coordinates

Using (x, y) positions is common.

However, you may use (r, Θ) r = distance from origin Θ = angle.

Converting between the two systems is easy. Just remember the name!

Page 9: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Rotational Mathematics

Beware, we need a little bit more sophistication to calculate the angle… as this gives us ambiguity.

Page 10: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Pythagoras & Collision Detection

We can use circle to circle collision as an example.

We find the centre of each circle and use Pythagoras to discover the distance between the two.

The equations to the right tell us when there has been a collicsion!

We can possibly do this with square distances to avoid using expensive sqrt operations.

We must be careful to avoid interpenetration as the entities will indefinite collide with each other.

Page 11: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Collision Detection Problems

Interpenetration of objects. Interlocking of objects. Quantum Tunnelling Effects.

Page 12: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Scaling

Once again in scaling we need to translate our object’s origin to the origin of the world, we then perform the scaling operation.

Remember to translate back!

Page 13: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Logic

We use logic all the time in coding.

We will use logic for our AI and decision making in games.

We will explicitly cover some rudimentary logic.

Page 14: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Truth Tables

And Or Not Xor Implies Tautologies—Saying the same thing more

than once. Associative Laws—Order does not matter. Distributive Laws—We can say things in

different ways that mean the same thing. Identity Laws

Page 15: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Truth Tables

Page 16: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Associative Laws/Distributive Laws

Page 17: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Sets

Sets can be used to make decisions.

Sets indicate belongingness.

Page 18: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Set Theory

Venn Diagrams Union Intersection Difference. Sets Subsets Compliment Universal Set Identity Laws

Page 19: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

A Intersect B

Page 20: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Multiple Sets

What is in A, B and C? What is in A? What is in not A?

Useful for games. Useful for determining

strategies.

Page 21: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

C++ and Sets

Yes!

std::set!

How awesome is that?

Page 22: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Vectors and Matrices

Vectors and matrices are mathematically convenient tools.

They are used in games for graphical mathematics.

So annoying that std::vector is named in such a way to make things a little confusing.

Page 23: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Mathematical Problems

I like to call this Quantum Tunnelling. We miss the detection of a collision as the bullet passes through the wall.

Page 24: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Simple Tricks

Bounding box collision detection in 2D. Bounding box collision

detection in 2D.

Page 25: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Today

Tricks One’s Compliment

Page 26: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Pythagoras

The distance between two points can be calculated using Pythagoras.

This can be used for simple collision detection.

Movie, https://www.youtube.com/watch?v=pVo6szYE13Y, accessed August 2014.

Page 27: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Simple Collision Detection

https://www.youtube.com/watch?v=o-OvVep2uSg, accessed August 2014.

Page 28: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Analytical Geometry

Analytical Geometry is concerned with points and the relationships between points.

We can find angles between two points to determine interesting relationships.

Page 29: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Distance Between Two Points

Useful for determining:

(a) If a collision would take place. (b) If a collision has taken place.

Page 31: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Vectors

Vectors can represent acceleration, velocity and displacement and any sort of force, which is essential to any physics orientated game.

It allows for you to calculate paths, trajectories and many aspects of physics within code.

Page 32: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Vector

A vector is a point.

For two dimensional mathematics: (x, y).

These vectors have interesting operations.

They make it easier to do mathematics.

Page 33: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Simple Idea

We can simply calculate the resulting vector when combining multiple forces…

Page 34: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Matrix

A matrix is a column by row matrix of values.

The matrix has defined operations so we can perform mathematical operations efficiently on a collection of points.

Page 35: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Translation Matrix

Page 36: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Scaling Matrix

Page 37: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

Rotation Matrix

Page 38: Some Cool Tricks.  We can consider the screen as high school graph paper.  Each sprite or object is located somewhere in the coordinate system

To Do

Read the wikipage on 2D Graphics. This will help you understand more

about your programming project.

http://en.wikipedia.org/wiki/2D_computer_graphics