C++ Game Animation Programming (eBook)
480 Seiten
Packt Publishing (Verlag)
978-1-80324-136-4 (ISBN)
If you're fascinated by the complexities of animating video game characters and are curious about the transformation of model files into 3D avatars and NPCs that can explore virtual worlds, then this book is for you. In this new edition, you'll find expanded content on high-performance graphics and modern animation techniques, along with improved workflows and enhanced guidance on using OpenGL and Vulkan. You'll learn everything you need to know about game animation, from a simple graphical window to a large crowd of smoothly animated characters.
First, you'll learn how to use modern high-performance graphics, dig into the details of how virtual characters are stored, and load the models and animations into a minimalistic game-like application. Then, you'll get an overview of the components of an animation system, how to play the animations and combine them, and how to blend from one animation into another. You'll also get an introduction to topics that will make your programming life easier, such as debugging your code or stripping down the graphical output.
By the end of this book, you'll have gained deep insights into all the parts of game animation programming and how they work together, revealing the magic that brings life to the virtual worlds on your screen.
Build your own OpenGL or Vulkan application in C++ and use it as a playground to explore the path from basic features to advanced techniques of character animation in modern games with the help of this illustrated guideKey FeaturesLearn how to create a game skeleton with keyboard and mouse controls along with modern graphicsGain insights into model loading, character animations, inverse kinematics, and debugging techniquesMaster the art of creating animated characters and controlling their various aspectsPurchase of the print or Kindle book includes a free PDF eBookBook DescriptionIf you're fascinated by the complexities of animating video game characters and are curious about the transformation of model files into 3D avatars and NPCs that can explore virtual worlds, then this book is for you. In this new edition, you ll learn everything you need to know about game animation, from a simple graphical window to a large crowd of smoothly animated characters. First, you ll learn how to use modern high-performance graphics, dig into the details of how virtual characters are stored, and load the models and animations into a minimalistic game-like application. Then, you ll get an overview of the components of an animation system, how to play the animations and combine them, and how to blend from one animation into another. You ll also get an introduction to topics that will make your programming life easier, such as debugging your code or stripping down the graphical output. By the end of this book, you ll have gained deep insights into all the parts of game animation programming and how they work together, revealing the magic that brings life to the virtual worlds on your screen.What you will learnCreate simple OpenGL and Vulkan applications and work with shadersExplore the glTF file format, including its design and data structuresDesign an animation system with poses, clips, and skinned meshesFind out how vectors, matrices, quaternions, and splines are used in game developmentDiscover and implement ways to seamlessly blend character animationsImplement inverse kinematics for your characters using CCD and FABRIK solversUnderstand how to render large, animated crowds efficientlyIdentify and resolve performance issuesWho this book is forThis book is for curious C++ developers, game programmers, game designers, and character animators, either pursuing this as a hobby or profession, who have always wanted to look behind the curtain and see how character animation in games works. The book assumes basic C++ and math knowledge, and you should be able to read code and math formulas to get the most out of this book.]]>
Preface
Character animations have existed since the first games were created for computers. The spaceships in SpaceWar!, written by Steve Russell in 1962 for a PDP-1, and Computer Space by Nolan Bushnell, released in 1971 as an arcade cabinet, were animated, with the animation showing the direction in which the spaceships headed.
Over time, the evolution of character animation went from these raster graphics, drawn by the electron beam inside the cathode-ray tube of old TV sets, to simple 2D pictures (so-called “sprites”). These sprites were drawn by hand, picture by picture, and every one of these pictures showed a different animation phase. To create the illusion of real-time animations, the pictures were shown quickly one after another, like cartoons. The main characters in Pac-Man and Super Mario Bros. are just a bunch of two-dimensional pictures, brought to life by proper timing between the sprites and their motion over the screen.
Eventually, the character models became real 3D objects. First, they were made of simply dozens of triangles, and as the graphics hardware became more powerful, the numbers got larger and larger. Current 3D models can have more than 500,000 polygons, and even these characters are animated smoothly in real time.
This book covers the animation of 3D game characters, taking a closer look at the principles of character components and animation. After explaining the theoretical elements of animation, we will provide an example implementation that will guide you from the conceptual stage to the real-world usage in an application. With this knowledge, you will be able to implement a similar animation system, regardless of the programming language or rendering API.
Who this book is for
This book is for programmers who want to “look behind the curtain” of character animation in games. You should be familiar with C++, and it would be best to have a modern version such as C++17. Basic knowledge of a rendering pipeline will come in handy too, but it is not required, as it will be covered in the book. The remaining skills, including opening a window, preparing a rendering API to draw triangles, and loading models and animating them, will also be explained throughout the book.
What this book covers
Chapter 1, Creating the Game Window, covers the initial steps to open a window using GLFW, a lightweight cross-platform window management library. The window will be enhanced to detect OpenGL 4.6 and Vulkan 1.1; code for handling window events such as resizing and moving will be added, followed by an introduction on using the keyboard and mouse as input devices.
Chapter 2, Building an OpenGL 4 Renderer, explains how to create a basic OpenGL 4 renderer that can display a textured quad consisting of two triangles.
Chapter 3, Building a Vulkan API Renderer, explores the creation of a renderer, similar to Chapter 2, but instead using the newer Vulkan API to display the textured quad.
Chapter 4, Working with Shaders, covers the different shaders of the graphics pipeline for OpenGL and Vulkan, the buffer types, and how to access the variables of shaders from renderer code. At the end of the chapter, the parts of a vertex and a fragment shader will be discussed.
Chapter 5, Adding Dear ImGui to Show Valuable Information, explains how to add a simple UI to both renderers to display information about the rendering process, such as the frames per second or timing of code sections. Also, checkboxes, buttons, and sliders will be added to the UI to control the rendering parameters.
Chapter 6, Understanding Vector and Matrix, is a quick recap of the data types of a vector and a matrix, their transformations, and their operations.
Chapter 7, A Primer on Quaternions and Splines, explains the advantage of quaternions over matrix operations and introduces some spline types that are used in game character animations.
Chapter 8, Loading Models in the glTF format, covers the internals of the glTF file format. glTF is an open file format, supported by many 3D content creation tools. Being able to load this format will let you view models and animations authored in many 3D creation tools in the application.
Chapter 9, The Model Skeleton and Skin, covers the internal skeleton of a model as a base for animation, plus vertex skinning to match different poses of the skeleton. Different methods to apply vertex skinning will be discussed in this chapter.
Chapter 10, About Poses, Frames, and Clips, explains the different data types required for character animation, allowing you to get from a simple model pose to a complete animation clip.
Chapter 11, Blending between Animations, shows different blending methods for animated mode. The chapter covers simple blending between a basic pose and an animation clip, cross-blending between different clips, and additive blending to mix different clips.
Chapter 12, Cleaning Up the User Interface, enhances the UI created in Chapter 4 with more
user-interactable elements, such as combo boxes and radio buttons. These controls enable the modification of animation parameters in real time. In addition, the timer values for the code sections will be visualized as graphical plots.
Chapter 13, Implementing Inverse Kinematics, explains how to use inverse kinematics to achieve an interaction between a character and its environment. The two inverse kinematics methods, Cyclic Coordinate Descent (CCD) and Forward And Backward Reaching Inverse Kinematics (FABRIK), will be explained and implemented.
Chapter 14, Creating Instanced Crowds, shows how to add more than one model to a scene, plus different ways to transfer model data to the graphics memory.
Chapter 15, Measuring Performance and Optimizing the Code, introduces methods to find bottlenecks by profiling code and using RenderDoc to analyze the graphics pipeline. It also offers ideas to move calculations from runtime to compile time and examines the importance of scaling to get meaningful results.
To get the most out of this book
To follow the code snippets and the example code, you should have some experience using C++. Any special or advanced features will be explained, and resources to learn more about these features are included in the chapters when they are first used. However, you should be able to debug simple C++ problems (e.g., by using logging statements).
The code in this book is written for OpenGL 4.6 and Vulkan 1.1. These versions are widely supported in modern GPUs; the oldest graphics cards known to work with these API versions are from the Intel HD Graphics 4000 series, created about 10 years ago.
| Software used in the book | Operating system requirements |
| OpenGL 4.6 and Vulkan 1.1 | Windows or Linux |
The example code presented in this book can be compiled on any desktop computer or laptop running a recent version of Windows and Linux. The code has been tested with the following combinations:
- Windows 10 with Visual Studio 2022
- Windows 10 with Eclipse 2023-06, using GCC from MSYS2 and Ninja as the build system
- Ubuntu 22.04 with Eclipse 2023-06, using GCC or Clang
- Ubuntu 22.04 compiling on the command line, using GCC or Clang
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.
The full source code for the examples is available from the book’s GitHub repository (a link is available in the next section). The chapters in the book contain only excerpts from the code, covering the important parts.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Cpp-Game-Animation-Programming-Second-Edition. 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...
| Erscheint lt. Verlag | 1.12.2023 |
|---|---|
| Sprache | englisch |
| Themenwelt | Mathematik / Informatik ► Informatik ► Grafik / Design |
| Informatik ► Programmiersprachen / -werkzeuge ► C / C++ | |
| Informatik ► Software Entwicklung ► Spieleprogrammierung | |
| Informatik ► Theorie / Studium ► Algorithmen | |
| ISBN-10 | 1-80324-136-5 / 1803241365 |
| ISBN-13 | 978-1-80324-136-4 / 9781803241364 |
| Informationen gemäß Produktsicherheitsverordnung (GPSR) | |
| Haben Sie eine Frage zum Produkt? |
Digital Rights Management: ohne DRM
Dieses eBook enthält kein DRM oder Kopierschutz. Eine Weitergabe an Dritte ist jedoch rechtlich nicht zulässig, weil Sie beim Kauf nur die Rechte an der persönlichen Nutzung erwerben.
Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belletristik und Sachbüchern. Der Fließtext wird dynamisch an die Display- und Schriftgröße angepasst. Auch für mobile Lesegeräte ist EPUB daher gut geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür die kostenlose Software Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür eine kostenlose App.
Geräteliste und zusätzliche Hinweise
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich