Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Some Cool Tricks Mathematics
Graphs • 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!
Translation • Moving things around is called translation. • Usually we translate our object to the origin before we perform rotation and scaling.
Translation • Move every point in one object to another location.
Rotation • For rotation, lets visit the Siggraph web page: https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm, accessed August 2014.
Pythagoras • We use Pythagoras to find the distance between two points.
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!
Rotational Mathematics • Beware, we need a little bit more sophistication to calculate the angle… as this gives us ambiguity.
Pythagoras & Collision Detection 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. • 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!
Collision Detection Problems • Interpenetration of objects. • Interlocking of objects. • Quantum Tunnelling Effects.
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!
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.
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
Sets • Sets can be used to make decisions. • Sets indicate belongingness.
Set Theory • Venn Diagrams • Union • Intersection • Difference. • Sets • Subsets • Compliment • Universal Set • Identity Laws
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.
C++ and Sets • Yes! • std::set! • How awesome is that?
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.
Mathematical Problems I like to call this Quantum Tunnelling. We miss the detection of a collision as the bullet passes through the wall.
Simple Tricks Bounding box collision detection in 2D. Bounding box collision detection in 2D.
Today • Tricks • One’s Compliment
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.
Simple Collision Detection • https://www.youtube.com/watch?v=o-OvVep2uSg, accessed August 2014.
Analytical Geometry • Analytical Geometry is concerned with points and the relationships between points. • We can find angles between two points to determine interesting relationships.
Distance Between Two Points • Useful for determining: • (a) If a collision would take place. • (b) If a collision has taken place.
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.
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.
Vector • A vector is a point. • For two dimensional mathematics: • (x, y). • These vectors have interesting operations. • They make it easier to do mathematics.
Simple Idea • We can simply calculate the resulting vector when combining multiple forces…
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.
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