Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

1,820 views

Published on

No Downloads

Total views

1,820

On SlideShare

0

From Embeds

0

Number of Embeds

1

Shares

0

Downloads

37

Comments

0

Likes

3

No embeds

No notes for slide

- 1. Introduction to Game Physics with Box2D2. Mathematics for Game Physics Lecture 2.1: Basic Math Ian Parberry Dept. of Computer Science & Engineering University of North Texas
- 2. Contents of This Lecture1. Geometry2. Vectors3. OrientationChapter 2 Introduction to Game Physics with Box2D 2
- 3. René Descartes• 1596 – 1650, French philosopher, physicist, physiologist, & mathematician.• Famous for (among other things) recognizing that linear algebra and geometry are the same thing.• Particularly useful for us, because the CPU does linear algebra and what we see on the screen is geometry.Chapter 2 Introduction to Game Physics with Box2D 3
- 4. GeometryChapter 2 Introduction to Game Physics with Box2D 4
- 5. 2.1.3 2.2.2 2.2.1 Vector Ball to Line Ball to Wall 3-7 3,4 Magnitude Collision Collision Chapters Chapters 2.1.3 2.2.2 2.1.4 Theorem of Vector Dot Vector 4, 5, 8 Pythagoras Product Orientation Chapters 2.1.3 2.1.4 Law of 6,8 Cosines Chapters 2.1.3 2.2.3 Pythagorean Ball to Ball Quadratic Identity Collision Equations 3,4 ChaptersChapter 2 Introduction to Game Physics with Box2D 5
- 6. Things You Might Remember From SchoolChapter 2 Introduction to Game Physics with Box2D 6
- 7. Trig FunctionsChapter 2 Introduction to Game Physics with Box2D 7
- 8. Mnemonics1. Sohcahtoa2. Some Old Horse Caught Another Horse Taking Oats Away.3. Some Old Hippy Caught Another Hippy Toking On Acid.Chapter 2 Introduction to Game Physics with Box2D 8
- 9. Theorem of PythagorasChapter 2 Introduction to Game Physics with Box2D 9
- 10. Proof of the Theorem of PythagorasChapter 2 Introduction to Game Physics with Box2D 10
- 11. Pythagorean IdentityChapter 2 Introduction to Game Physics with Box2D 11
- 12. Law of CosinesChapter 2 Introduction to Game Physics with Box2D 12
- 13. Proof of the Law of CosinesChapter 2 Introduction to Game Physics with Box2D 13
- 14. More Useful Trig IdentitiesChapter 2 Introduction to Game Physics with Box2D 14
- 15. VectorsChapter 2 Introduction to Game Physics with Box2D 15
- 16. What’s Our Vector, Victor?Chapter 2 Introduction to Game Physics with Box2D 16
- 17. Programming Vectors• Vectors correspond very naturally to an array in most programming languages.• D3DX has a structure D3DXVECTOR2 that we will use to implement 2D vectors in code.• A D3DXVECTOR2 v has two floating point fields v.x and v.y.Chapter 2 Introduction to Game Physics with Box2D 17
- 18. Chapter 2 Introduction to Game Physics with Box2D 18
- 19. Vector Multiplication by a ScalarChapter 2 Notes 3D Math Primer for Graphics & Game Dev 19
- 20. Vector Addition: AlgebraChapter 2 Notes 3D Math Primer for Graphics & Game Dev 20
- 21. Vector Addition: Geometry = =Chapter 2 Introduction to Game Physics with Box2D 21
- 22. Vector Addition in Code D3DXVECTOR2 u, v, w; v = D3DXVECTOR2(3.1415f, 7.0f); u = 42.0f * v; w = u + D3DXVECTOR2(v.x, 9.0f); u += w;Chapter 2 Introduction to Game Physics with Box2D 22
- 23. Vector MagnitudeChapter 2 Introduction to Game Physics with Box2D 23
- 24. Vector NormalizationChapter 2 Introduction to Game Physics with Box2D 24
- 25. Vector Magnitude in Code• D3DXVec2Normalize normalizes a D3DXVECTOR2, that is, makes its length 1.• D3DXVec2Length computes the length of a D3DXVECTOR2. – Square roots are expensive. – Often it is just as easy to work with squares of vector lengths as with lengths. – If so, use the faster D3DXVec2LengthSq function instead of D3DXVec2Length.Chapter 2 Introduction to Game Physics with Box2D 25
- 26. OrientationChapter 2 Introduction to Game Physics with Box2D 26
- 27. Relative OrientationChapter 2 Introduction to Game Physics with Box2D 27
- 28. OrientationChapter 2 Introduction to Game Physics with Box2D 28
- 29. Length & Orientation to Vector Step 1. Step 2. Step 3.Chapter 2 Introduction to Game Physics with Box2D 29
- 30. Vector to Orientation Step 2. Step 1. Step 3.Chapter 2 Introduction to Game Physics with Box2D 30
- 31. A GotchaChapter 2 Introduction to Game Physics with Box2D 31
- 32. Rotating a VectorChapter 2 Introduction to Game Physics with Box2D 32
- 33. Rotating a VectorChapter 2 Introduction to Game Physics with Box2D 33
- 34. Rotating a VectorChapter 2 Introduction to Game Physics with Box2D 34
- 35. Vector Rotation Code void Rotate(const D3DXVECTOR2& u, D3DXVECTOR2& v, float beta){ float alpha = atan2(u.y, u.x); v.x = cos(alpha + beta); v.y = sin(alpha + beta); } //RotateThis works but we can do better. The atan2can be optimized out.Chapter 2 Introduction to Game Physics with Box2D 35
- 36. Optimizing the Rotation CodeChapter 2 Introduction to Game Physics with Box2D 36
- 37. Optimized Vector Rotation Code void Rotate(const D3DXVECTOR2& u, D3DXVECTOR2& v, float beta){ v.x = u.x * cos(beta) - u.y * sin(beta); v.y = u.x * sin(beta) + u.y * cos(beta); } //RotateWe’ve replaced an arctangent with four floatingpoint multiplications, which is faster in practice.Chapter 2 Introduction to Game Physics with Box2D 37
- 38. ConclusionChapter 2 Introduction to Game Physics with Box2D 38
- 39. Suggested ReadingSection 2.1 Suggested Activities Problems 1-4 from Section 2.5.Chapter 2 Introduction to Game Physics with Box2D 39

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment