Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mathematics for Game Programming and Computer Graphics

You're reading from  Mathematics for Game Programming and Computer Graphics

Product type Book
Published in Nov 2022
Publisher Packt
ISBN-13 9781801077330
Pages 444 pages
Edition 1st Edition
Languages
Author (1):
Penny de Byl Penny de Byl
Profile icon Penny de Byl

Table of Contents (26) Chapters

Preface 1. Part 1 – Essential Tools
2. Chapter 1: Hello Graphics Window: You’re On Your Way 3. Chapter 2: Let’s Start Drawing 4. Chapter 3: Line Plotting Pixel by Pixel 5. Chapter 4: Graphics and Game Engine Components 6. Chapter 5: Let’s Light It Up! 7. Chapter 6: Updating and Drawing the Graphics Environment 8. Chapter 7: Interactions with the Keyboard and Mouse for Dynamic Graphics Programs 9. Part 2 – Essential Trigonometry
10. Chapter 8: Reviewing Our Knowledge of Triangles 11. Chapter 9: Practicing Vector Essentials 12. Chapter 10: Getting Acquainted with Lines, Rays, and Normals 13. Chapter 11: Manipulating the Light and Texture of Triangles 14. Part 3 – Essential Transformations
15. Chapter 12: Mastering Affine Transformations 16. Chapter 13: Understanding the Importance of Matrices 17. Chapter 14: Working with Coordinate Spaces 18. Chapter 15: Navigating the View Space 19. Chapter 16: Rotating with Quaternions 20. Part 4 – Essential Rendering Techniques
21. Chapter 17: Vertex and Fragment Shading 22. Chapter 18: Customizing the Render Pipeline 23. Chapter 19: Rendering Visual Realism Like a Pro 24. Index 25. Other Books You May Enjoy

Preface

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 more detail. Python, together with Pygame and PyOpenGL, provides the opportunity for today’s developers to explore these features under the hood, revealing how computers generate and manipulate 3D environments.

Mathematics for Game Programming and Computer Graphics is a comprehensive 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, working with vertex shaders, and implementing physics techniques such as collisions and particle emitters. Using Python, Pygame, and PyOpenGL, you will create your own mathematical-based engine and API that will be used throughout to build applications and examples.

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

When Packt first approached me to write this book, I had just released a course on computer graphics using Python and OpenGL in Udemy and on H3DLearn.com. The timing was never better than to review what I had learned in the course and write it up in a book focused on the mathematics involved.

Mathematics is one of those topics you either love, loathe, or have a quiet appreciation for. I was in the loathe camp for most of my university studies. I found it irritating and a time-consuming function I needed to get done to continue with my love of programming. Then, in my honors (fourth year), I was introduced to computer graphics and fractals. It was like a veil had been lifted for me and mathematics became magical, fascinating, and most importantly, visual. Being able to see the beauty in mathematics changed everything. I’m still not a lover of mathematics, but I’ve definitely gone from the loathe stage to quiet appreciation. Though I guess writing a book about it takes me from just appreciating it to love. You can’t program any computer games or graphics without knowing the mathematics driving it all.

My goal in writing this book is to bring you into the “quiet appreciation” category. If you get to the “love” category, then great! I do believe that we all have different talents. Mathematics is not mine. I do find it quite challenging, but I have persevered and, over my career, learned to understand its origin and application. I am in no way one of those people who can multiply tens of numbers in my head, but I don’t need to be. The point is that if you learn when and where to apply the mathematics, and then transform that into a programming algorithm, and you can validate and be confident of the output, then it doesn’t matter whether you can calculate the output in your head or need time to work it out.

There’s just so much mathematics to cover in this area that I could have honestly written another several hundred pages. However, it’s my hope that the content herein will fire you up and give you the confidence and critical skills to independently further your education.

Who this book is for

This book is for programmers who want to better their 3D mathematics skills relating to computer graphics and computer games. Knowledge of high-school-level mathematics and a working understanding of an object-orientated language will be required.

What this book covers

Chapter 1, Hello Graphics Window: You’re On Your Way, introduces the software tools used throughout the book to explore 3D graphics and game development, where Python and OpenGL will be used to develop graphical window applications.

Chapter 2, Let’s Start Drawing, takes you through a series of exercises to set up and explore the basic skeleton code required to run and update a graphics application.

Chapter 3, Line Plotting Pixel by Pixel, contains a series of exercises to explore low-level line drawing algorithms, beginning with a naive approach that will reveal the issues involved in drawing lines on a raster display.

Chapter 4, Graphics and Game Engine Components, investigates the software architecture of games and graphics engines the associated data structures for working with 3D environments.

Chapter 5, Let’s Light It Up!, shows you how to bring light and texture to a virtual scene to develop solid models of previously used meshes.

Chapter 6, Updating and Drawing the Graphics Environment, takes you through a series of exercises designed to reveal the cyclical nature of producing graphics frames in addition to building a strong foundation for your graphics project.

Chapter 7, Interactions with the Keyboard and Mouse for Dynamic Graphics Programs, teaches you how to use the Pygame API to gather user input via the mouse and keyboard and use it to interact with a game environment.

Chapter 8, Reviewing Our Knowledge of Triangles, reviews trigonometry with an aim to solidify the concepts of similar triangles and the mathematical properties of right-angle triangles.

Chapter 9, Practicing Vector Essentials, investigates the mathematical principles of vectors and explores the link between their properties and right-angle triangles to reveal the many ways they are useful in graphics.

Chapter 10, Getting Acquainted with Lines, Rays, and Normals, explores the similarities and differences between straight geometric elements and applies them to object movement.

Chapter 11, Manipulating the Light and Texture of Triangles, investigates the use of normal vectors in computer graphics and discovers how they are essential for representing, drawing, and lighting 3D models.

Chapter 12, Mastering Affine Transformations, reveals the primary set of operations that allows 3D points and models to be translated, scaled, and rotated in 3D space.

Chapter 13, Understanding the Importance of Matrices, discusses how transformations are represented as matrices and the power this brings to processing computer graphics.

Chapter 14, Working with Coordinate Spaces, teaches you about the different coordinate spaces a vertex is transformed through to get from its local coordinate system to a pixel on the screen.

Chapter 15, Navigating the View Space, guides you to explore ways to move the camera around in a 3D environment as well as discover some glitches in the matrix operations for rotations.

Chapter 16, Rotating with Quaternions, takes you deeper into the highly complex domain of quaternion rotations and shows how 4D spaces can solve 3D rotational issues.

Chapter 17, Vertex and Fragment Shading, guides you through the programming of shader code for the drawing of objects that transfers graphics from CPU control to be processed in parallel on the graphics card.

Chapter 18, Customizing the Render Pipeline, explores some fundamental techniques used to write shader code for elementary shaders that produce lighting effects.

Chapter 19, Rendering Visual Realism Like a Pro, reveals how light physically interacts with a 3D environment and the objects within it to develop a modern physically based rendering shader.

To get the most out of this book

The scripting language used in this book is Python. You should be familiar with coding in Python or at the very least have a working knowledge of an object-orientated programming language, such as C# or C++. Later in the book, when the OpenGL Shader Language is introduced, skills in this area are not required. Though an understanding of how procedural languages, such as C, are formatted would be beneficial. The projects created herein have been tested in the macOS and Windows environments.

Software covered in the book

Operating system requirements

Python

Windows or macOS

Pygame

Windows or macOS

PyOpenGL

Windows or macOS

PyCharm

Windows or macOS

OpenGL Shader Language (GLSL)

Windows or macOS

The downloading and setup instructions for this list of software are covered in the book as they are required.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Mathematics-for-Game-Programming-and-Computer-Graphics. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/rmsvT.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The color() method takes the red, green, and blue channels, respectively, as arguments.”

A block of code is set as follows:

import pygame pygame.init()screen_width = 800 screen_height = 200 screen = pygame.display.set_mode((screen_width,                  screen_height))

done = False white = pygame.Color(255, 255, 255)pygame.font.init()font = pygame.font.SysFont(‘Comic Sans MS’, 120, False, True)text = font.render(‘Penny de Byl’, False, white)while not done:  for event in pygame.event.get():    if event.type == pygame.QUIT:      done = True   screen.blit(text, (10, 10))  pygame.display.update()pygame.quit()

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

background = pygame.image.load(‘images/background.png’)sprite = pygame.image.load(‘images/Bird-blue-icon.png’)while not done:  for event in pygame.event.get():    if event.type == pygame.QUIT:      done = True   screen.blit(background, (0, 0))  screen.blit(sprite, (100, 100))
  pygame.display.update()pygame.quit()

Any command-line input or output is written as follows:

tick=2, fps=714.2857055664062
tick=1, fps=714.2857055664062
tick=1, fps=714.2857055664062
tick=1, fps=666.6666870117188
tick=2, fps=666.6666870117188

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Now, all you have to do is press Play to see the results.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Download a Free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781801077330

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon The rest of the chapter is locked
Next Chapter arrow right
You have been reading a chapter from
Mathematics for Game Programming and Computer Graphics
Published in: Nov 2022 Publisher: Packt ISBN-13: 9781801077330
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}