Hands-On C++ Game Animation Programming

Book description

Learn animation programming from first principles and implement modern animation techniques that can be integrated into any game development workflow

Key Features

  • Build a functional and production-ready modern animation system with complete features using C++
  • Learn basic, advanced, and skinned animation programming with this step-by-step guide
  • Discover the math required to implement cutting edge animation techniques such as inverse kinematics and dual quaternions

Book Description

Animation is one of the most important parts of any game. Modern animation systems work directly with track-driven animation and provide support for advanced techniques such as inverse kinematics (IK), blend trees, and dual quaternion skinning.

This book will walk you through everything you need to get an optimized, production-ready animation system up and running, and contains all the code required to build the animation system. You’ll start by learning the basic principles, and then delve into the core topics of animation programming by building a curve-based skinned animation system. You’ll implement different skinning techniques and explore advanced animation topics such as IK, animation blending, dual quaternion skinning, and crowd rendering. The animation system you will build following this book can be easily integrated into your next game development project. The book is intended to be read from start to finish, although each chapter is self-contained and can be read independently as well.

By the end of this book, you’ll have implemented a modern animation system and got to grips with optimization concepts and advanced animation techniques.

What you will learn

  • Get the hang of 3D vectors, matrices, and transforms, and their use in game development
  • Discover various techniques to smoothly blend animations
  • Get to grips with GLTF file format and its design decisions and data structures
  • Design an animation system by using animation tracks and implementing skinning
  • Optimize various aspects of animation systems such as skinned meshes, clip sampling, and pose palettes
  • Implement the IK technique for your game characters using CCD and FABRIK solvers
  • Understand dual quaternion skinning and how to render large instanced crowds

Who this book is for

This book is for professional, independent, and hobbyist developers interested in building a robust animation system from the ground up. Some knowledge of the C++ programming language will be helpful.

Table of contents

  1. Hands-On C++ Game Animation Programming
  2. Why subscribe?
  3. Contributors
  4. About the author
  5. About the reviewer
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Conventions used
    4. Get in touch
      1. Reviews
  8. Chapter 1: Creating a Game Window
    1. Technical requirements
    2. Creating an empty project
    3. Creating the application class
    4. Adding an OpenGL loader
    5. Getting glad
      1. Adding glad to the project
    6. Creating a window
      1. Global variables
      2. Opening a window
      3. Creating the event handler
    7. Exploring the samples
    8. Summary
  9. Chapter 2: Implementing Vectors
    1. Introducing vectors
    2. Creating a vector
      1. Epsilon
    3. Understanding component-wise operations
      1. Vector addition
      2. Vector subtraction
      3. Scaling vectors
      4. Multiplying vectors
      5. Dot product
    4. Understanding non-component-wise operations
      1. Vector length
      2. Normalizing vectors
      3. The angle between vectors
      4. Vector projection and rejection
      5. Vector reflection
      6. Cross product
    5. Interpolating vectors
    6. Comparing vectors
    7. Exploring more vectors
    8. Summary
  10. Chapter 3: Implementing Matrices
    1. Technical requirements
    2. What is a matrix?
      1. Matrix storage
    3. Creating a matrix
    4. Common matrix operations
      1. Comparing matrices
      2. Adding matrices
      3. Scaling a matrix
      4. Matrix multiplication
    5. Transforming vectors and points
    6. Inverting a matrix
      1. Transpose
      2. Determinant and minors of lower-order matrices
    7. Creating camera matrices
      1. Frustum
      2. Perspective
      3. Orthographic
      4. Look at
    8. Summary
  11. Chapter 4: Implementing Quaternions
    1. Creating quaternions
      1. Angle axis
      2. Creating rotations from one vector to another
    2. Retrieving quaternion data
    3. Common quaternion operations
    4. Comparison operations
    5. Dot product
    6. Length and squared length
    7. Unit quaternions
    8. Conjugate and inverse
    9. Multiplying quaternions
    10. Transforming vectors
    11. Interpolating quaternions
      1. Neighborhood
      2. Understanding the mix function
      3. Understanding the nlerp function
      4. Introduction to slerp
      5. Power
      6. Implementing slerp
    12. Look rotation
    13. Converting between quaternions and matrices
    14. Summary
  12. Chapter 5: Implementing Transforms
    1. Creating the transform
    2. Combining transforms
    3. Inverting transforms
    4. Mixing transforms
    5. Converting transforms to matrices
    6. Converting matrices into transforms
    7. Transforming points and vectors
    8. Summary
  13. Chapter 6: Building an Abstract Renderer
    1. Technical requirements
    2. Working with shaders
      1. The Shader class declaration
      2. Implementing the Shader class
    3. Working with buffers (attributes)
      1. The Attribute class declaration
      2. Implementing the Attribute class
    4. Working with uniforms
      1. The Uniform class declaration
      2. Implementing the Uniform class
    5. Working with index buffers
      1. The IndexBuffer class declaration
      2. Implementing the IndexBuffer class
    6. Rendering geometry
    7. Working with textures
      1. Adding stb_image
      2. The Texture class declaration
      3. Implementing the Texture class
    8. Simple shaders
      1. The vertex shader
      2. The fragment shader
    9. Summary
  14. Chapter 7: Exploring the glTF File Format
    1. Technical requirements
    2. Exploring how glTF files are stored
      1. glTF files store a scene, not a model
    3. Exploring the glTF format
      1. The parts you need for animation
      2. The parts you don't need for animation
      3. Accessing data
    4. Exploring cgltf
      1. Integrating cgltf
    5. Exploring the sample assets
      1. Exporting from Blender
    6. Summary
  15. Chapter 8: Creating Curves, Frames, and Tracks
    1. Understanding cubic Bézier splines
    2. Understanding cubic Hermite splines
    3. Interpolation types
    4. Creating the Frame struct
    5. Creating the Track class
      1. Declaring the Track class
      2. Implementing the Track class
    6. Creating the TransformTrack class
      1. Declaring the TransformTrack class
      2. Implementing the TransformTrack class
    7. Summary
  16. Chapter 9: Implementing Animation Clips
    1. Implementing poses
      1. Declaring the Pose class
      2. Implementing the Pose class
    2. Implementing clips
      1. Declaring the Clip class
      2. Implementing the Clip class
    3. glTF – loading the rest pose
    4. glTF – loading joint names
    5. glTF – loading animation clips
    6. Summary
  17. Chapter 10: Mesh Skinning
    1. Exploring meshes
    2. Understanding skinning
      1. Exploring rigid skinning
      2. The rigid skinning pipeline
      3. Exploring smooth skinning
    3. Implementing skeletons
      1. The Skeleton class declaration
      2. The Skeleton class implementation
    4. glTF – loading the bind pose
    5. glTF – loading a skeleton
    6. Implementing meshes
      1. The Mesh class declaration
      2. The Mesh class implementation
    7. glTF – loading meshes
    8. Implementing GPU skinning
    9. Summary
  18. Chapter 11: Optimizing the Animation Pipeline
    1. Pre-generating the skin matrix
      1. Generating the skin matrix
      2. CPU skinning
      3. GPU skinning
    2. Storing the skin palette in a texture
    3. Faster sampling
      1. Optimizing the Track class
      2. Converting tracks
      3. Creating FastTransformTrack
      4. Creating FastClip
    4. The Pose palette generation
      1. Changing the GetMatrixPalette function
      2. Reordering joints
      3. Reordering clips
      4. Reordering meshes
    5. Exploring Pose::GetGlobalTransform
    6. Summary
  19. Chapter 12: Blending between Animations
    1. Pose blending
      1. Declaring the Blend function
      2. Implementing the Blend function
    2. Crossfading animations
      1. Creating helper classes
      2. Declaring the cross-fade controller
      3. Implementing the cross-fade controller
    3. Additive blending
      1. Declaring additive animations
      2. Implementing additive animations
    4. Summary
  20. Chapter 13: Implementing Inverse Kinematics
    1. Creating a CCD solver
      1. Declaring the CCD solver
      2. Implementing the CCD solver
    2. Creating a FABRIK solver
      1. Declaring the FABRIK solver
      2. Implementing the FABRIK solver
    3. Implementing constraints
      1. Ball-and-socket constraint
      2. Hinge constraint
    4. Using IK to align a character's feet to the ground
      1. Finding the foot goals
      2. Interpolating the foot goals
      3. Vertical character placement
      4. IK pass
      5. Foot alignment
    5. Summary
    6. Further reading
  21. Chapter 14: Using Dual Quaternions for Skinning
    1. Introducing dual quaternions
    2. Implementing dual quaternions
      1. Implementing dual quaternion operations
      2. Measuring, normalizing, and inverting dual quaternions
      3. Converting transforms and dual quaternions
      4. Transforming vectors and points
    3. Skinning with dual quaternions
      1. Modifying the pose class
      2. Modifying the skeleton class
      3. Creating new uniform types
      4. Creating a dual quaternion shader
    4. Understanding how to use dual quaternion skinning
    5. Summary
  22. Chapter 15: Rendering Instanced Crowds
    1. Storing data in textures
    2. Reading data from textures
    3. Encoding animation data
    4. Exploring per-instance data
    5. Creating an animation texture
      1. Declaring the AnimTexture class
      2. Implementing the AnimTexture class
    6. Animation baker
    7. Creating a crowd shader
    8. Creating the Crowd utility class
      1. Implementing the Crowd class
      2. Using the Crowd class
    9. Blending animations
    10. Exploring texture formats
    11. Combining animation textures
    12. Optimizing texel fetches
      1. Limiting influences
      2. Limiting animated components
      3. Not interpolating
      4. Combining these optimizations
    13. Summary
  23. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On C++ Game Animation Programming
  • Author(s): Gabor Szauer
  • Release date: June 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781800208087