Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
C++ Game Animation Programming - Second Edition

You're reading from  C++ Game Animation Programming - Second Edition

Product type Book
Published in Dec 2023
Publisher Packt
ISBN-13 9781803246529
Pages 480 pages
Edition 2nd Edition
Languages
Concepts
Authors (2):
Michael Dunsky Michael Dunsky
Profile icon Michael Dunsky
Gabor Szauer Gabor Szauer
Profile icon Gabor Szauer
View More author details

Table of Contents (22) Chapters

Preface 1. Part 1:Building a Graphics Renderer
2. Chapter 1: Creating the Game Window 3. Chapter 2: Building an OpenGL 4 Renderer 4. Chapter 3: Building a Vulkan Renderer 5. Chapter 4: Working with Shaders 6. Chapter 5: Adding Dear ImGui to Show Valuable Information 7. Part 2: Mathematics Roundup
8. Chapter 6: Understanding Vector and Matrix 9. Chapter 7: A Primer on Quaternions and Splines 10. Part 3: Working with Models and Animations
11. Chapter 8: Loading Models in the glTF Format 12. Chapter 9: The Model Skeleton and Skin 13. Chapter 10: About Poses, Frames, and Clips 14. Chapter 11: Blending between Animations 15. Part 4: Advancing Your Code to the Next Level
16. Chapter 12: Cleaning Up the User Interface 17. Chapter 13: Implementing Inverse Kinematics 18. Chapter 14: Creating Instanced Crowds 19. Chapter 15: Measuring Performance and Optimizing the Code 20. Index 21. Other Books You May Enjoy

10

About Poses, Frames, and Clips

Welcome to Chapter 10! In the previous chapter, we introduced the model skeleton and the process of vertex skinning on the CPU and GPU. We also explored vertex skinning using dual quaternions as an alternative to linear interpolation to achieve better volume retention.

In this chapter, we will discuss the main topic of the book: game character animations. The steps taken in the previous chapters and the code we created were just the prerequisites for creating the animations in this chapter.

We start with a general definition of the terms used for various parts of the animations in the rest of the book. Next, we will examine how the animation data is stored in the glTF file format, how to extract the data, and how the glTF model will be altered during the animations.

At the end of the chapter, we will use the knowledge we have gained to create C++ classes for the animations and integrate these new classes into the renderers and the user...

Technical requirements

To follow along in this chapter, you will need the OpenGL and Vulkan renderer code from Chapter 9.

Before we start examining the animations in the glTF file format, let’s take a quick look at the parts of the animations, their names, and how they relate to each other.

A brief overview of animations

Today’s game character animations are completely different from the 2D animations from cartoons created about 100 years ago, such as the famous cartoons by Walt Disney in the 1930s. But there are still a lot of similarities between modern computer animations and the hand-drawn animations of the past.

glTF animations are based on key poses. Every animation has at least a starting and an ending key pose, and most animations also have many key poses at specific points in time. If the starting and the ending key poses are the same, or similar, the animation can be played in a continuous loop. But if these two key poses are too different, another animation must follow at the end, or the direction of the animation must be reversed.

To fill the time between the key poses, intermediate frames are calculated. While intermediate frames had to be drawn by hand in the past, the calculations in modern 3D animations are done by interpolating the vertex...

Pouring the knowledge into C++ classes

We will split the code for the animations into two separate classes to follow the structure of the glTF file format. In a glTF file, the animation clips and the animation channels are stored in different elements because one animation clip uses data from multiple animation channels.

The first class, named GltfAnimationChannel, will contain the data of a glTF animation channel. We will store all data of a single channels entry and the corresponding samplers entry in this class: the time points from the input buffer, the new data for the target node from the output buffer, the interpolation type from the sampler, plus the target path and the target node from the channel definition.

The second class, GltfAnimationClip, manages the animation clips and uses the GltfAnimationChannel class to store the animation channel data per clip.

Storing the channel data in a class

We start the animation channel class, GltfAnimationChannel, with the...

Summary

In this chapter, we finally arrived at the point where we were able to animate our loaded glTF model in the renderers we started in Chapter 2 and Chapter 3.

First, we got a broad overview of the different elements of animations and the model poses. Then, we analyzed the animation elements of the glTF file format, the sub-element channels and samplers, and the relations of these elements to the other parts of the glTF model, such as the joints and nodes.

Finally, we created two new C++ classes for managing the glTF channels and the animation clips and included these classes in the renderer. We also added new UI elements to the application, allowing fine-grained control of various parameters of the animations.

In the next chapter, we will dive deeper into the realms of game character animations. We will explore different forms of animation blending, such as the blending between the binding pose as a “still pose”, where the model does not move, and the full...

Practical sessions

Try out the following ideas to enhance the code for the animation playback:

  • Add a class to append multiple animation clips to a longer animation track. You could join the running and jumping clips to create the illusion of a long-running glTF model by playing jump animation clips between a couple of running animation clips.
  • Add the ability to control the looping of an animation, such as not only switching the loop on and off, but also controlling the number of loops to play in a row. The animation should stop after the last loop has finished.
  • Add a UI control and the logic to play the clips backward. For many clips, this will result in quite interesting behavior of the model, but animations such as sitting and leaning will become more meaningful. The model will stand up from a sitting position and lean back to the upright position.

Additional resources

lock icon The rest of the chapter is locked
You have been reading a chapter from
C++ Game Animation Programming - Second Edition
Published in: Dec 2023 Publisher: Packt ISBN-13: 9781803246529
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 AU $19.99/month. Cancel anytime}