Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Mathematics for Game Programming and Computer Graphics
Mathematics for Game Programming and Computer Graphics

Mathematics for Game Programming and Computer Graphics: Explore the essential mathematics for creating, rendering, and manipulating 3D virtual environments

Arrow left icon
Profile Icon Penny de Byl
Arrow right icon
NZ$80.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (12 Ratings)
Paperback Nov 2022 444 pages 1st Edition
eBook
NZ$44.99 NZ$64.99
Paperback
NZ$80.99
Subscription
Free Trial
Arrow left icon
Profile Icon Penny de Byl
Arrow right icon
NZ$80.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (12 Ratings)
Paperback Nov 2022 444 pages 1st Edition
eBook
NZ$44.99 NZ$64.99
Paperback
NZ$80.99
Subscription
Free Trial
eBook
NZ$44.99 NZ$64.99
Paperback
NZ$80.99
Subscription
Free Trial

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Colour book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Mathematics for Game Programming and Computer Graphics

Hello Graphics Window: You’re On Your Way

Students new to games and computer graphics fall into two camps: ones that think mathematics is a real bore and of no real use, and others that realize it is akin to breathing. The fact is that if you want to be successful (and stay alive) in the domain, then you can’t deny the importance of mathematics. This doesn’t mean that learning about it should be a grind. What we find most exciting about teaching and learning about mathematics in the computer games and graphics space is that the equations and numbers come alive through visual representations that remain otherwise unseen in other fields. Throughout this book, you will learn the essential mathematics in games and graphics by exploring the theory surrounding each topic and then utilizing it in real-world applications.

To this end, throughout this book, you will not only gain an understanding of the essential mathematics that is used throughout games and graphics, but also apply its principles in one of today’s hottest programming languages: Python.

Note

As the content of this book relates to both computer graphics and computer games, rather than continually typing out the laborious phrase “computer graphics and computer games,” we will endeavor to refer to both collectively as graphics.

“Why Python?” we hear you ask. “Why not some fancy game’s engine?” Well, besides having Python programming as a great skill under your belt when it comes to applying for a job, Python with the assistance of PyCharm (our Integrated Development Environment – IDE), Pygame (a graphics interface), and PyOpenGL (a Python/OpenGL API) reveals much of the underlying technical processes hidden by game engines and brings you face to face with direct calls to the graphics APIs that access OpenGL and DirectX. It’s a more challenging way to learn about mathematics if you remove all the high-level methods available to you that hide how your applied mathematics programming skills are working.

Learning about the mathematics of computer games and graphics at this level is essential in your learning journey. In this ever-changing domain, as technology progresses, your theoretical level of the how’s and why’s of the topic can remain constant and make you a highly skilled and adaptive programmer. A deep-seated knowledge of the algorithms and equations running the APIs of contemporary games and graphics engines is critical and transferable knowledge that developers can take from one platform to another and from one API to another. It not only provides extra insight while troubleshooting and debugging, but also gives a programmer an intuitive understanding of what functionality an API might contain without actually knowing that API. It’s akin to understanding all the tools in Adobe Photoshop and being able to perceive what tools will be available in Affinity Photo without ever using it. Having good math skills blurs the line between what is possible and what is not.

Now that you know why you are learning about mathematics in the way presented throughout this book, it’s time to dive into getting your own development environment set up and exploring the anatomy of a simple graphics window that will become the basis of all our exercises moving forward. We will begin with a guided exercise in getting your own development environment setup using PyCharm. This will allow you to jump right into coding with as little fuss as possible. It removes the need to manually download and install packages and plugins that usually require knowledge of command-line install procedures, which can become laborious and vary between desktop machine setups. This means more time spent on coding to start using Python to open windows and explore the range of fundamental graphics drawing methods that will set you up for graphics development success.

In this chapter, we will cover the following topics:

  • Getting Started with Python, PyCharm, and Pygame
  • Creating a Basic Graphics Window
  • Working with Window and Cartesian Coordinates

Technical requirements

As mentioned in the introduction, we will be using the programming language, Python, along with an editor called PyCharm and a plugin/graphics library called Pygame. You should be a programmer to embark on the content of this course but not necessarily a Python programmer, as someone with working knowledge in any procedural language will pick up Python quickly enough.

These are all cross-platform tools and can be used on Windows, macOS, and Linux. We’ll leave it up to you to find the relevant versions of the software for your machine, however, to get you started, download Python from python.org. As shown in Figure 1.1, under the Downloads tab, you can get the latest version of the software. At the time of writing, it is Python 3.10.0. It is highly recommended that you follow along with the exercises in this book using the versions shown in the book to reduce any errors you may come across in replicating the code. If you are reading this and there is a later version of Python available, you can find version 3.10.0 under the All releases option as follows:

Figure 1.1: The Downloads tab at python.org

Figure 1.1: The Downloads tab at python.org

Thus, the steps to get Python installed on your machine are as follows:

  1. Visit python.org and download a version of Python relevant to your operating system.
  2. Run the downloaded file and follow the directions to install the software.

In order to code and compile with Python, we require an editor; for this, we will be using PyCharm. The same advice stands for version numbers of this software. At the time of writing this book, PyCharm is on version 2021.3. There is a Profession and a free Community version of PyCharm, but we will only require the free version for this book. To install PyCharm on your machine, do as follows:

  1. Visit www.jetbrains.com/PyCharm/download.
  2. Download a version of the installer relevant to your machine.
  3. Run the installer to set up PyCharm.

Now that you have the fundamental software installed, we will proceed to create a basic graphics window before learning how to draw on the screen.

Getting Started with Python, PyCharm, and Pygame

In this section, we will go through the process of setting up PyCharm and rendering a graphics window on the screen. To do this, follow these steps:

  1. Open PyCharm. The first window will appear as shown in Figure 1.2.
Figure 1.2: The opening PyCharm screen on an Apple Mac (the screen on other platforms will look similar but not the same)

Figure 1.2: The opening PyCharm screen on an Apple Mac (the screen on other platforms will look similar but not the same)

You may want to take some time to look at the Customize section. This will allow you to set up colors, fonts, and other visual components. There are also many different settings and customizations you can make within PyCharm, and if you ever want to explore these, then we recommend a visit to the manual at www.jetbrains.com/help/PyCharm/quick-start-guide.html.

  1. Next, select the New Project button on the Projects page of the startup window. A window like what is shown in Figure 1.3 will appear.
Figure 1.3: PyCharm’s New Project window and settings

Figure 1.3: PyCharm’s New Project window and settings

  1. Next, we need to set up our new project as follows:
    1. For Location (1), create a new folder for your files. Unlike a single source file such as what you might get with a Word document, a Python project can consist of many files. Therefore, instead of specifying a single file name, you must specify a folder. Call it Mathematics.
    2. In the field for Base interpreter (2), ensure that you select the version of Python that you downloaded and installed. It’s possible to have more than one version of Python installed on your machine. This is useful if you are working on different projects for clients as you can set the version when you create a new project.
    3. When you first open the New Project window, the Create a main.py welcome script tickbox (3) will be ticked. We don’t require a default main.py script and therefore you should untick it.
  2. Once the project settings have been entered, click on the Create button.
  3. As shown in Figure 1.4, after PyCharm opens the new project window, it will display a column on the left with the folder structure (1). By clicking on Python Packages at the bottom of the window (2), a new section will be revealed where you can search and install packages. In the search section (3), type Pygame. This will bring up a list of packages below the search area. Select the one at the top that says Pygame, and then on the right, click the Install button (4). Once Pygame has been installed, you can close the packages section (5).
Figure 1.4: The PyCharm interface and package installation window

Figure 1.4: The PyCharm interface and package installation window

Python, PyCharm, and Pygame are now set up, and you are ready to create your first graphics window.

For those new to Python

If you are new to Python but not programming, it is a straightforward language to pick up. To get up to speed quickly, any newbies are encouraged to read over the beginner’s documentation at https://wiki.python.org/moin/BeginnersGuide.

Creating a Basic Graphics Window

It’s time to create your first basic graphics window in PyCharm. To do this, perform the following steps:

  1. Right-click on the project folder (1), as shown in Figure 1.5.
Figure 1.5: Creating a new Python script file (steps 1-5)

Figure 1.5: Creating a new Python script file (steps 1-5)

  1. Select New > Python File (2).
  2. In the popup window, enter the name of your new Python script (3). In this case, it will be HelloWindow.py. There’s no need to add the .py suffix as PyCharm will add this for you. Hit the Enter/Return key.
  3. Once the file has been created, you will see it in the Project section of PyCharm (4).
  4. The file will also be open and displayed on the left as a tab title (5). The window below the tab is where you will type in your code as follows:
    import pygame
    pygame.init()
    screen_width = 1000
    screen_height = 800
    screen = pygame.display.set_mode((screen_width,
                     screen_height))

The preceding code imports the Pygame library, so you can access the methods provided by Pygame to set up graphics windows and display images. The specific method used in this case is set_mode(), which creates and returns a display surface object.

Tool tip

There are no semi-colons at the end of lines in Python. Although, if you accidentally use one because it’s second nature to you as a programmer, then it’s very forgiving and ignores them.

The editor will also insist on variables and methods being written in snake_case (www.codingem.com/what-is-snake-case/) where separate works are joined by a delimiter, such as an underscore. You can see this format in the previous code in the variable named screen_width.

When complete, the window will look like Figure 1.6.

Figure 1.6: Code entered into PyCharm to generate a basic graphics window

Figure 1.6: Code entered into PyCharm to generate a basic graphics window

It is not the aim of this book to teach you Python or the ins and outs of the Pygame library as we want to focus on mathematics; however, short explanations will be given as we add new features. In this case, the first line ensures that the functionality of the Pygame package is included with the code, which allows us to use the methods embedded inside Pygame. Next, we initialize the Pygame environment on line 2. Finally, we create a screen (a graphics window or surface also known as a display). The width of this window is 1,000 pixels by 800 pixels in height.

If you are unsure of what the parameters of a method are, simply mouse over/hover your cursor the method and PyCharm will pop open a hint box with more information about the method.

  1. The code can now be run. To do this, right-click on the HelloWindow.py filename in the Project window and then select Run HelloWindow’, as shown in Figure 1.7:
Figure 1.7: Running code for the first time

Figure 1.7: Running code for the first time

If you’ve typed in the code correctly, a window with dimensions of 1,000 x 800 will pop open and then immediately close. It might be too fast to see, so try running it again. You will know the program has been completed without error as the console now visible at the bottom of the PyCharm window will display an exit code of 0, as shown in Figure 1.8:

Figure 1.8: When a program runs without error, it will return an exit code of 0

Figure 1.8: When a program runs without error, it will return an exit code of 0

Note that once you’ve run code for the first time, it becomes available as a run option in the top toolbar and can be easily run again using the green play button at the top of the PyCharm window. Ensure that the filename next to the button is the one you want to run, as shown in Figure 1.9:

Figure 1.9: Running the previous code again

Figure 1.9: Running the previous code again

  1. In its current state, the graphics window isn’t much help to us if it won’t stay open. Therefore, we need to force it to stay open. You see that as the code executes line by line, once it reaches the end, the compiler considers the program to be finished. All graphics windows need to be forced to stay open with an endless loop that runs until a specific condition is reached. Game engines inherently have this built in and call it the main game loop. As you will discover in Chapter 6, Updating and Drawing the Graphics Environment, the main loop is the heartbeat of all graphics programs. In this case, we must create our own. To do this, modify the code by adding the highlighted text to your program as follows:
    import pygame
    pygame.init()
    screen_width = 1000
    screen_height = 800
    screen = pygame.display.set_mode((screen_width,
                     screen_height))
    done = False
    while not done:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          done = True
      pygame.display.update()
    pygame.quit()

Tool tip

Instead of relying on braces, for example, ‘{‘ and ‘}’ to segment code blocks, Python relies on indentation, and at the end of a line with a Boolean expression, you will always find a full colon (:).

You’ve just created an endless loop that will keep running until the window is manually closed by the user. The done variable is initially set to false, and only when it becomes true can the loop end. pygame.event.get() returns a list of events the window has received since the last loop. These can be keystrokes, mouse movements, or any other user input. In this case, we are looking for pygame.QUIT to have occurred. This event is signaled by the attempted closing of the window. The final pygame.quit() method safely closes down all Pygame processes before the window closes.

  1. Run the program again. This time, the graphics window will stay open. It can be closed using the regular window closing icons that appear on the top bar of the window (on the left in Mac OS and on the right in Windows).
  2. Because code will be reused and updated from chapter to chapter, the best way to organize it all would be to place all the code for a chapter into its own folder. So, let’s create a folder for Chapter One. To do this, right-click on the Mathematics project folder at the top and then select New > Directory, as shown in Figure 1.10. Name the folder Chapter_One.
  3. Drag and drop HelloWindow.py into the new folder. PyCharm will ask you to refactor the code and it’s fine to go ahead and do so. You can now keep all the code from any chapter in one place even when the same script names are used.
  4. Figure 1.10: Creating a new directory inside PyCharm

Figure 1.10: Creating a new directory inside PyCharm

And that’s it. Your first basic graphics window. Keep a copy of this code handy as you will need to use it as the basis of all projects from this point forward. Whenever we ask you to create a new Python file in PyCharm, this code will be the jumping-off point.

Hints

To further help you with creating a window, consider the following points:

- If you haven’t used Python before but are familiar with other programming languages, the absence of brackets and braces for the sectioning of code will feel a little odd at first. Instead of brackets, Python uses indentation. You can read more about this at www.geeksforgeeks.org/indentation-in-python/.

- Python does not need semicolons at the end of lines.

- Whenever you encounter methods or properties used in the code that you are unfamiliar with, it is a good exercise for your own independent learning to investigate these in the Python and Pygame API listings as follows:

- For Pygame, see www.pygame.org/docs/genindex.html.

- For Python, see docs.python.org/3/library/index.html.

- As you may have noticed as you were typing out the code, Python can be fussier than other programming languages when it comes to formatting and syntax. PyCharm will give you suggestions for most formatting issues by showing warning symbols at the end of problem lines or drawing a rippled line under methods and variables. A right-click on these will reveal suggestions for fixes. For a more extensive list, however, see www.python.org/dev/peps/pep-0008/.

This section has been a whirlwind of an introduction to opening a basic graphics window. Knowing how to achieve this is fundamental to the exercises in the remainder of this book or the start of your own graphics or game projects, as it is the key mechanic that supports all these types of applications. In the next section, we will expand on your knowledge of the graphics window by exploring its coordinates and layout.

Working with Window and Cartesian Coordinates

Remember drawing an x- and y-axis on paper in school and then plotting a point based on its x and y value? This was the beginning of your journey into the Cartesian coordinate system. You likely use it every day to locate positions on maps, in drawings, or on your computer screen. Fundamentally, it is a way of uniquely representing a location with a single value on a line, a pair of numerical coordinates on a plane (2D), or with a triplet of values in 3D. In fact, Cartesian coordinates even extend into four, five, and upward dimensions, though they aren’t relevant here.

The axes of the system have evenly spaced measurements, much like a ruler, and are used to determine where a location made up of coordinates is placed. For example, in one dimension there is only one axis, and going with popular convention, we will call this x. To plot x = 5 is to locate the value of 5 on the axis and place a point there. In two dimensions with the axes, x and y, and the coordinate (2, 3) where x is the first value and y is the latter, a point is placed where these values intersect. These examples are illustrated in Figure 1.11.

Figure 1.11: Cartesian plots of x = 5 in one dimension (a) and (2,3) in two dimensions (b)

Figure 1.11: Cartesian plots of x = 5 in one dimension (a) and (2,3) in two dimensions (b)

The majority (if not all) of graphics applications work in two and three dimensions and as such we will reduce our discussion in this book to those with most applications in 3D. While the computer screen is 2D, it is also used to fake 3D; however, the mathematics applied still occurs within 3D calculations with the x-, y-, and z- axes. In working with graphics, we must therefore be aware of different ways of viewing Cartesian coordinates. In the next exercise, we will show the plotting of points in 2D and how Cartesian coordinates work in graphics.

Let’s do it…

To create a window with some plotted points defined by Cartesian coordinates, we perform the following steps:

  1. Create a new Python script called PlotPixel.py and add the following code (the differences between HelloWindow.py and this script are shown in bold):
    import pygame
    pygame.init()
    screen_width = 1000
    screen_height = 800
    screen = pygame.display.set_mode((screen_width,
                     screen_height))
    done = False
    white = pygame.Color(255,255,255)
    while not done:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          done = True
      screen.set_at((100, 100),white)
      pygame.display.update()
    pygame.quit()
  2. The set_at() method will plot a single pixel point in the color of your choosing; in this case, the pixel will be white at the coordinates x = 100, and y = 100. To see this in action, run the script. Remember that you will need to right-click on the filename in the Project window and select Run before you’ll be able to run it from the little green icon at the top-right of the window. Now, try plotting another point at (200, 200). You can do this with a second set_at() call, for example, as follows:
    screen.set_at((200, 200),white)

The resulting screen image is shown in Figure 1.12 (note that the pixel locations have been enhanced with white squares so you can see them in print).

Figure 1.12: Pixel locations when plotted in a default window

Figure 1.12: Pixel locations when plotted in a default window

What did you notice about the location of the pixels? Based on their position, where would you conclude the origin (0,0) of the window to be?

If you said the upper-left corner of the window, you would be correct. We all learn in school that the positive Cartesian coordinate system runs for positive x values to the right along the page and for positive y values up the page. However, in computer graphics, this isn’t true, and the coordinate systems will follow different conventions depending on the platform and tools. In this case, the x coordinates run as you would expect but the y values are inverted with positive y values going down the page.

Why? Because early graphics displays used physical, electron scan lines beginning in the upper-left corner of the display, scanning across, and then down. It doesn’t need to be like this anymore, but it just is.

Most game engines transform these coordinates so that the y-axis faces up.

However, as the astute computer graphics programmer that you are, it’s always best to figure out which way is up according to the coordinate system you are working with, either through the documentation or by running a few experiments of your own.

  1. If you would prefer the origin of the coordinate system to be shown in the lower left-hand corner, then you can modify the coordinates with a simple method as follows:
    import pygame
    pygame.init()
    screen_width = 1000
    screen_height = 800
    screen = pygame.display.set_mode((screen_width,
                     screen_height))
    done = False
    white = pygame.Color(255, 255, 255)
    def to_pygame_coordinates (display, x, y):
      return x, display.get_height() - y
    while not done:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          done = True
              screen.set_at(to_pygame_coordinates 
                            (screen, 100,100),
                             white)
              screen.set_at(to_pygame_coordinates 
                            (screen, 200,200),
                             white)
      pygame.display.update()
    pygame.quit()

In the preceding code, the new to_pygame_coordinates() method flips the y coordinate based on the screen height and returns a new set of (x, y) values for plotting the pixel basing the origin of the screen in the lower-left corner of the window. Though, after you’ve worked with graphics for a while, you’ll get used to the upper-left origin and as such we will assume the origin of the coordinates (0,0) to be the upper-left of the graphics window, unless stated otherwise.

Drawing rectangles

In the preceding figure, we used rectangles to enhance the size of the pixels to make them visible. To draw a point in a location in the window that is larger than a single pixel, we can draw a small rectangle or square instead. To do this, the code is as follows:

import pygame

pygame.init()

screen_width = 1000

screen_height = 800

screen = pygame.display.set_mode((screen_width, screen_height))

done = False

white = pygame.Color(255, 255, 255)

def to_pygame_coordinates(display, x, y):

return x, display.get_height() - y

while not done:

for event in pygame.event.get():

if event.type == pygame.QUIT:

done = True

position = to_pygame_coordinates

(screen, 100, 100)

pygame.draw.rect(screen, white,

(position[0],position[1],

10, 10))

pygame.display.update()

pygame.quit()

The definition of pygame.draw.rect can be found at https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect. In short, a rectangle requires a screen, color, a starting location (identified by position in the code), and a width and height (we are using 10 in this example).

This task has shown you how to work with a window and the coordinates used within it. It’s a valuable skill as pixel-by-pixel is how every graphics application is written. It’s the nature of the display devices we use.

Your Turn…

Note

After most code-along exercises in the Let’s do it… sections of this book, you will find a section like this that encourages you to apply the skills you’ve learned thus far. The answers to these exercises can be found at the end of the chapter.

Exercise A.

Find an image of the constellation representing the Leo star sign and draw those series of stars on the screen. An example of its layout is shown in Figure 1.13. Notice that we have also included a size factor for each star based on its relative brightness, where we used rectangles of different sizes to draw each one.

Figure 1.13: The constellation of Leo

Figure 1.13: The constellation of Leo

When you have completed this and reviewed the answer at the end of the chapter, why not try and recreate your own star sign?

Summary

You are now an expert at opening graphics windows and have new-found skills at plotting pixels in that window using Cartesian coordinates. This skill is the essential underpinning of everything that gets drawn on a computer screen; it’s through the understanding of mathematics that you will gain throughout this book that you will be able to expand that single pixel into a world of complex 3D structures, colors, and animations. Some of these basic graphics primitives will be explored in the following chapter.

Answers

Exercise A:

import pygame
pygame.init()
screen_width = 900
screen_height = 500
screen = pygame.display.set_mode((screen_width, screen_height))
done = False
white = pygame.Color(255, 255, 255)
def draw_star(x, y, size):
  pygame.draw.rect(screen, white, (x, y, size, size))
while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
  draw_star (121, 320, 15)
  draw_star (327, 324, 15)
  draw_star (691, 431, 20)
  draw_star (697, 317, 10)
  draw_star (626, 246, 30)
  draw_star (343, 212, 10)
  draw_star (653, 165, 10)
  draw_star (773, 102, 10)
  draw_star (822, 153, 10)
  pygame.display.update()
pygame.quit()
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • 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

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.

Who is this book 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.

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
Estimated delivery fee Deliver to New Zealand

Standard delivery 10 - 13 business days

NZ$20.95

Premium delivery 5 - 8 business days

NZ$74.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 30, 2022
Length: 444 pages
Edition : 1st
Language : English
ISBN-13 : 9781801077330
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Colour book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to New Zealand

Standard delivery 10 - 13 business days

NZ$20.95

Premium delivery 5 - 8 business days

NZ$74.95
(Includes tracking information)

Product Details

Publication date : Nov 30, 2022
Length: 444 pages
Edition : 1st
Language : English
ISBN-13 : 9781801077330
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just NZ$7 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total NZ$ 205.97 228.97 23.00 saved
Applying Math with Python
NZ$73.99
Mathematics for Game Programming and Computer Graphics
NZ$80.99
C# 11 and .NET 7 – Modern Cross-Platform Development Fundamentals
NZ$50.99 NZ$73.99
Total NZ$ 205.97 228.97 23.00 saved Stars icon
Banner background image

Table of Contents

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

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9
(12 Ratings)
5 star 91.7%
4 star 8.3%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




N/A Apr 04, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Feefo Verified review Feefo
Justin Horner Jan 11, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Math and graphics programming are two of my favorite topics, so of course I was excited to discover Penny de Byl and Packt were teaming up to deliver this new book.As a big fan of her work (she has courses and other books you can check out at holistic3d.com), my expectations were high, and I'm happy to report this book does not disappoint!Using Python, Pygame, and PyOpenGL, you'll go from learning about Bresenham's algorithm for line rendering to lighting, essential trigonometry, and rendering techniques like vertex and fragment shading and customizing the rendering pipeline.It was refreshing to see the use of Python and graphics libraries over a game engine like Unity and Unreal, and I hope to see more books cover such topics in a similar fashion.This book is an excellent resource to add to your library.I can easily recommend it.
Amazon Verified review Amazon
SoImpossible Dec 25, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A wonderful introduction to vectors, dot products and cross products. This is the book I wish I had when I started learning gamedev in my childhood. The Python code is very accessible. Although I will transfer the gamedev concepts into Rust, Python is ideal for learning the mathematical concepts. OpenGL’s Matrix Stack is well explained. I was always fascinated by Quaternions and this book does not disappoint. Vertex and Fragment Shading is also well explained.The only thing I would improve regarding this book… I would love to see the Python code with additional coding languages to implement the same functionality, perhaps Rust and C++. A sort of comparative gamedev reference of different coding languages.The concepts are taught brilliantly and this book is now a reference on those techniques which I am already learning. Python is understandably the best language to teach these concepts in. A brave decision. Although I cannot wait to implement these concepts in Rust.Another valuable book from Packt.
Amazon Verified review Amazon
Peter J. Jonas Mar 18, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Mathematics and programming can sound scary to many people. And here is a book that contains them both.And I am one of the odd ones who love both topics, so I was excited when I received my copy.Even though I don’t do computer graphics and I don’t even plan to do it, I really enjoy this book. (Yep, that’s true; I haven’t finished yet.)The reason is I love this book that I do work with 3D virtual environments. I do game audio design, and I can use this book as well as a graphics designer can.Penny leads us through the basics of 3D creation and manipulation from the very beginning.Straightforward-to-follow, clear and direct-to-the-point explanations, and (personally, I love Python), Python is an easy-to-digest and understandable language. It is not essential here, even if you have not yet learned it. Once you understand mathematics, you can apply it to any programming language.I strongly recommend this book if you want (or need) to know mathematics in programming. And it is not just for Graphics Designers but anyone working in 3D environments.
Amazon Verified review Amazon
Christopher West Feb 16, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you're looking to get into game development or computer graphics and you're worried about the math involved, then "Mathematics for Game Programming and Computer Graphics" by Penny De Byl might just be the book you need. This book takes you through all the math concepts you need to know, from the basics of linear algebra and calculus to more advanced topics like vectors, matrices, transformations, curves, surfaces, and shading.One of the things I really appreciated about this book was how practical it is. The author doesn't just present you with a bunch of abstract concepts and formulas; she shows you how to use them to solve real-world problems. You'll learn about collision detection, physics simulation, and 3D rendering, and you'll get plenty of opportunities to practice what you've learned through exercises and programming assignments.The book is also very well-organized and easy to follow. Each chapter builds on the previous one, so you don't feel like you're getting lost or overwhelmed with information. And the author uses plenty of helpful illustrations and diagrams to explain the concepts, so you don't have to rely solely on text to understand what's going on.Overall, I'd definitely recommend "Mathematics for Game Programming and Computer Graphics" if you're looking for a practical, approachable way to learn the math behind game development and computer graphics. It's a great resource for anyone who wants to turn their passion for games or art into a career.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela