Mathematics for Game Programming and Computer Graphics

Book description

A comprehensive guide to learning fundamental 3D mathematical principles used in games and computer graphics by example

Key Features

  • Get acquainted with the essential mathematics needed to describe, simulate, and render 3D creations
  • Construct and manipulate 3D animated environments using Python, Pygame, and PyOpenGL
  • Develop vertex and fragment shaders in OpenGL shader language to speed up rendering

Book Description

Mathematics is an essential skill when it comes to graphics and game development, particularly if you want to understand the generation of real-time computer graphics and the manipulation of objects and environments in a detailed way. Python, together with Pygame and PyOpenGL, provides you with the opportunity to explore these features under the hood, revealing how computers generate and manipulate 3D environments.

Mathematics for Game Programming and Computer Graphics is an exhaustive guide to getting “back to the basics” of mathematics, using a series of problem-based, practical exercises to explore ideas around drawing graphic lines and shapes, applying vectors and vertices, constructing and rendering meshes, and working with vertex shaders. By leveraging Python, Pygame, and PyOpenGL, you’ll be able to create your own mathematics-based engine and API that will be used throughout to build applications.

By the end of this graphics focussed book, you’ll have gained a thorough understanding of how essential mathematics is for creating, rendering, and manipulating 3D virtual environments and know the secrets behind today’s top graphics and game engines.

What you will learn

  • Get up and running with Python, Pycharm, Pygame, and PyOpenGL
  • Experiment with different graphics API drawing commands
  • Review basic trigonometry and how it’s important in 3D environments
  • Apply vectors and matrices to move, orient, and scale 3D objects
  • Render 3D objects with textures, colors, shading, and lighting
  • Work with vertex shaders for faster GPU-based rendering

Who this book is for

This book is for programmers who want to enhance their 3D mathematics skills relating to computer graphics and computer games. Knowledge of high school–level mathematics and a working understanding in an object-orientated language is needed to grasp the contents present in this book.

Table of contents

  1. Mathematics for Game Programming and Computer Graphics
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Download a Free PDF copy of this book
  6. Part 1 – Essential Tools
  7. Chapter 1: Hello Graphics Window: You’re On Your Way
    1. Technical requirements
    2. Getting Started with Python, PyCharm, and Pygame
    3. Creating a Basic Graphics Window
    4. Working with Window and Cartesian Coordinates
      1. Let’s do it…
      2. Your Turn…
    5. Summary
      1. Answers
  8. Chapter 2: Let’s Start Drawing
    1. Technical requirements
    2. Color
      1. Let’s do it…
      2. Your turn…
    3. Lines
      1. Let’s do it…
      2. Your turn…
      3. Let’s do it…
    4. Text
      1. Let’s do it…
      2. Your turn…
    5. Polygons
      1. Let’s do it…
      2. Your turn…
    6. Raster Images
      1. Let’s do it…
    7. Summary
    8. Answers
  9. Chapter 3: Line Plotting Pixel by Pixel
    1. Technical requirements
    2. The Naïve Way: Drawing a line with brute force
      1. Let’s do it…
    3. Enter Bresenham: The improved approach
      1. Let’s do it…
    4. Drawing circles the Bresenham way
      1. Let’s do it…
    5. Anti-aliasing
    6. Summary
  10. Chapter 4: Graphics and Game Engine Components
    1. Technical requirements
    2. Exploring the OpenGL Graphics Pipeline
      1. Let’s do it…
    3. Drawing Models with Meshes
      1. Let’s do it…
      2. Your turn…
    4. Viewing the Scene with Cameras
    5. Projecting Pixels onto the Screen
    6. Understanding 3D Coordinate Systems in OpenGL
      1. Perspective Projection
      2. Your turn…
      3. Projecting into the NDC
      4. Let’s do it…
      5. Your turn…
    7. Summary
    8. Answers
  11. Chapter 5: Let’s Light It Up!
    1. Technical requirements
    2. Adding Lighting Effects
      1. Let’s do it…
      2. Your turn…
    3. Placing Textures on Meshes
      1. Let’s do it…
      2. Let’s do it…
    4. Summary
    5. Answers
  12. Chapter 6: Updating and Drawing the Graphics Environment
    1. Technical requirements
    2. Introducing the main game loop
    3. Updating and drawing objects
      1. Let’s do it…
      2. Your turn…
    4. Measuring time
      1. Let’s do it…
    5. Summary
    6. Answers
  13. Chapter 7: Interactions with the Keyboard and Mouse for Dynamic Graphics Programs
    1. Technical requirements
    2. Working with mouse interactions
      1. Let’s do it…
      2. Your turn…
      3. Combining 2D and 3D environments
      4. Let’s do it…
      5. Converting the mouse to projection coordinates
      6. Let’s do it…
      7. Your turn…
      8. Let’s do it…
    3. Adding keyboard commands
      1. Let’s do it…
      2. Your turn…
      3. Let’s do it…
    4. Summary
    5. Answers
  14. Part 2 – Essential Trigonometry
  15. Chapter 8: Reviewing Our Knowledge of Triangles
    1. Technical requirements
    2. Comparing similar triangles
    3. Working with right-angled triangles
      1. Your turn…
    4. Calculating angles with sine, cosine, and tangent
      1. Investigating triangles by drawing 3D objects
    5. Summary
    6. Answers
  16. Chapter 9: Practicing Vector Essentials
    1. Technical requirements
    2. Understanding the difference between points and vectors
      1. Defining vector key operations
      2. Let’s do it…
    3. Working out a vector’s magnitude
      1. Your turn…
    4. Exploring the relationship between angles and vectors
      1. The dot product
      2. The cross product
    5. Summary
    6. Answers
  17. Chapter 10: Getting Acquainted with Lines, Rays, and Normals
    1. Technical requirements
    2. Defining lines, segments, and rays
    3. Using the parametric form of lines
      1. Your turn…
      2. Let’s do it…
    4. Calculating and displaying normals
      1. Your turn…
      2. Let’s do it…
      3. Your turn…
    5. Summary
    6. Answers
  18. Chapter 11: Manipulating the Light and Texture of Triangles
    1. Technical requirements
    2. Displaying Mesh Triangle Normals
      1. Let’s do it…
    3. Defining polygon sides with normals
      1. Working with visible sides of a polygon
    4. Culling Polygons According to the Normals
      1. Let’s do it…
      2. Let’s do it…
    5. Exploring How Normals Affect Lighting
      1. Let’s do it…
    6. Summary
  19. Part 3 – Essential Transformations
  20. Chapter 12: Mastering Affine Transformations
    1. Technical requirements
    2. Translating points in 3D
      1. Your turn…
    3. Scaling points with x, y, and z
      1. Let’s do it…
      2. Your turn…
    4. Rotating points around a pivot
      1. Let’s do it…
    5. Exploring transformation orders
    6. Shearing and reflections
    7. Summary
    8. Answers
  21. Chapter 13: Understanding the Importance of Matrices
    1. Technical requirements
    2. Defining matrices
    3. Performing operations on matrices
      1. Adding and subtracting matrices
      2. Multiplying by a single value
      3. Dividing matrices
    4. Creating matrix representations of affine transformations
      1. Moving from linear equations to matrix operations
      2. Compounding affine transformations
    5. Combining transformation matrices for complex maneuvers
      1. Let’s do it…
    6. Summary
    7. Answers
  22. Chapter 14: Working with Coordinate Spaces
    1. Technical requirements
    2. Understanding OpenGL’s Matrix Stack
    3. Working with the Model Matrix
      1. Let’s do it…
      2. Your turn…
    4. Working with the View Matrix
      1. Let’s do it…
    5. Working with the Projection Matrix
      1. Let’s do it…
      2. Your turn…
    6. Summary
    7. Answers
  23. Chapter 15: Navigating the View Space
    1. Technical requirements
    2. Flying maneuvers
      1. Let’s do it…
      2. Your turn...
    3. Understanding and fixing compound rotation quirks
    4. Improving camera orientations
      1. Let’s do it…
    5. Summary
    6. Answers
  24. Chapter 16: Rotating with Quaternions
    1. Technical requirements
    2. Introducing quaternions
    3. Rotating around an arbitrary axis
    4. Exploring quaternion spaces
      1. Let’s do it…
    5. Working with unit quaternions
      1. Your turn…
    6. Understanding the purpose of normalization
      1. Let’s do it...
      2. Your turn...
    7. Summary
    8. Answers
  25. Part 4 – Essential Rendering Techniques
  26. Chapter 17: Vertex and Fragment Shading
    1. Technical requirements
    2. Understanding shaders
    3. Transferring processing from the CPU to the GPU
      1. Let’s do it…
    4. Processing pixel by pixel
      1. Let’s do it…
    5. Summary
  27. Chapter 18: Customizing the Render Pipeline
    1. Technical requirements
    2. Coloring and texturing mesh faces
      1. Let’s do it…
      2. Let’s do it…
      3. Your turn...
    3. Turning on the lights
      1. Ambient lighting
      2. Diffuse lighting
      3. Phong
    4. Summary
    5. Answers
  28. Chapter 19: Rendering Visual Realism Like a Pro
    1. Technical requirements
    2. Following where light bounces
    3. Applying the Inverse Square Law
    4. Calculating Bidirectional Reflectance
      1. Distribution functions
      2. The Fresnel effect
      3. Geometric attentuation factor
    5. Putting it all together
      1. Let’s do it…
    6. Summary
  29. Index
    1. Why subscribe?
  30. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Download a Free PDF copy of this book

Product information

  • Title: Mathematics for Game Programming and Computer Graphics
  • Author(s): Penny de Byl
  • Release date: November 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781801077330