Foundations of Physically Based Modeling & Animation


Note that the code provided below is offered as is. The documentation is currently sparse, but will eventually be augmented, so it would be good to check from time to time for updates. Code supporting graphics uses traditional OpenGL and the GLUT interface. We plan to eventually rewrite the code using the current OpenGL standard, so again check for updates.

C++ Code Resources:

  • Linear Algebra Classes
  • This is a set of matrix and vector classes that is written to be easy to use and understand. Most student projects will run very well using these classes, and they make programming very simple, since matrix and vector operations are supported via operator overloading, allowing equations to be written using algebraic syntax. If highly optimized code is needed, we recommend use of the Eigen C++ Template Library.

  • Quaternion Class
  • This quaternion class is designed to work with the above linear algebra classes. All of the standard quaternion operations are supported as well the conversions between rotation matrices and quaternions, and rotation of a vector by a quaternion. In addition, a routine is provided that will do an OpenGL rotation directly from a quaternion.

  • Camera Class
  • This class provides a basic OpenGL 3D camera, that is manipulated by the mouse. Left mouse tilts and swings the camera around the object being viewed, middle mouse rotates the camera about its viewpoint, and right mouse zooms in and out.

  • Framegrabber Code
  • This code provides the ability to grab a sequence of animation frames into numbered image files, from which a video can be made. The code depends upon the ImageMagick Magick++ API.

  • Gaussian Random Number Function
  • A basic gaussian random number generator built on top of the linux drand48 routine. The user can specify mean, standard deviation, and an optional seed.

Example Programs:

  • OpenGL Example
  • For students who have not used OpenGL before, this example program provides a simple setup that will draw a ball and a cube and allow some basic mouse motion. It does not use the camera class (provided above), but many students have been able to use it as a good starting place for their first assignment.

Demonstration Programs:

  • 2D Bouncing Ball Demo
  • A program that can be used to demonstrate the falling ball problem covered in Chapter 2, as well as a 2D version of the bouncing ball covered in Chapter 3.

  • Spring Demo
  • A program that can be used to demonstrate a simple spring. It is similar to the Spring-Mass-Damper demo below, but has a simpler interface and visual representation, and gives interactive control over the various parameters using keystrokes.

  • Spring-Mass-Damper Demo
  • A program that can be used to demonstrate how a damped spring works, showing how the various parameters affect the decay time constant and the oscillation period. Optionally, one of the parameters (mass, spring, and damping constants) can be removed to show how the system behaves.

  • Euler, RK2, RK4 Integrator Demo
  • A program that shows how Euler, RK2, and RK4 perform when integrating a simple 1st order decay, or a simple undamped oscillator. The time step can be varied as a function of the decay time constant, or the oscillation period.

Reader Supplied Materials:

The links below are to code submitted by readers. The brief explanations and code are supplied as is.

  • Signed Distance Fields

    Submitted by Christoph Heindl: Pretty early in the book you state that signed distance functions (SDF) wouldn't be covered. Being quite a fan of signed distance functions - I've used them in the past for surface reconstruction - I thought that I would assemble some notes on them geared towards collision test and response for particle systems. I've put everything together in a Python notebook that shows particles interacting in an environment represented by a SDF. Everything is at the supplied github link, it's the second link under applications. The particles heavily use the formulations given in your book. The implementation is based on CGraph, a little library of mine, that allows symbolic computation in Python. As such, SDFs can be modeled as continous algebraic functions, later discretized when performance is needed.

Foundations of Physically Based Modeling & Animation