Some Cool Tricks. We can consider the screen as high school graph paper. Each sprite or object is...
-
Upload
alvin-jefferson -
Category
Documents
-
view
213 -
download
0
Transcript of Some Cool Tricks. We can consider the screen as high school graph paper. Each sprite or object is...
![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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/1.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/2.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/3.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/4.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/5.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/6.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/7.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/8.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/9.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/10.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/11.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/12.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/13.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/14.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/15.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/16.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/17.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/18.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/19.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/20.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/21.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/22.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/23.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/24.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/25.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/26.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/27.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/28.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/29.jpg)
Distance Between Two Points
Useful for determining:
(a) If a collision would take place. (b) If a collision has taken place.
![Page 30: Some Cool Tricks. We can consider the screen as high school graph paper. Each sprite or object is located somewhere in the coordinate system.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/30.jpg)
Perpendicular Distance Between Line and Point
Let’s look at the diagrams! http://
www.intmath.com/plane-analytic-geometry/perpendicular-distance-point-line.php, accessed August 2014.
![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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/31.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/32.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/33.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/34.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/35.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/36.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/37.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022070415/56649e7b5503460f94b7d0c4/html5/thumbnails/38.jpg)
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