# COL865: Physics-Based Animation Assignment 0: Setting Up

This assignment is not worth any points, and you do not have to submit anything. It is only to make sure you can produce animated results from your computer graphics code, which you will need to be able to do for future assignments. You should get this set up now, so you won’t have to waste time later worrying about rendering instead of working on the actual simulation problem.

## Requirements

The following procedure makes a rudimentary animation of a waving flag. Consider a rectangular array of vertices indexed by $$i=0,\dots,3n$$ and $$j=0,\dots,2n$$. At time $$t$$ seconds, let the $$(i,j)$$th vertex be at the position \begin{aligned} x &= u, \\ y &= v, \\ z &= \frac1{20}\,u \sin(2\pi(u + v - t)),\end{aligned} where $$u = i/n$$, $$v = j/n$$. The surface of the flag is constructed by connecting these vertices via polygons: either quadrilaterals of the form $$(i,j),(i+1,j),(i+1,j+1),(i,j+1)$$, or two triangles for each such quadrilateral.

Write a program to create this animation. Generate renderings in two styles:

1. A basic particle view where each vertex is drawn as a dot or a sphere, with edges (drawn as lines or cylinders) connecting adjacent pairs of vertices $$(i,j),(i+1,j)$$ and $$(i,j),(i,j+1)$$.

2. A surface view where the vertices themselves are not drawn, but the flag is drawn as a continuous surface by connecting the vertices using quadrilaterals or triangles. Make sure you add some lighting so that the waves in the surface can be easily seen.

To add some context to the animation, you could also draw a flag pole along the $$y$$-axis, and a floor plane at some negative $$y$$.

Create videos of your animation in both rendering styles. In future assignments in this course, one of the things you will have to submit with each assignment is the video(s) showing your results, so make sure you are able to generate such videos of your program. Some suggestions for how to do so are given below.

You may implement your program any way you like, as long as you are doing the animation part entirely within your own code instead of e.g. using a 3D graphics package to define the vertices and the wave motion. Here are some possible approaches:

• Write a standalone program that displays the animation interactively in real time using OpenGL. To create the videos, you may either use a screen capturing utility, or capture the rendered image at each frame within your program and save it to a new file (e.g. using the SOIL library if in C++). The latter may be preferable in future assignments, if the computation for high-resolution examples becomes too expensive to run in real time.

• Write a program that does no rendering, but simply computes the geometry of the surface (i.e. the positions of all the vertices, and the connecting polygons) at each frame and writes it out to a file. Use an external tool such as a 3D graphics program like Blender or Maya, or a high-quality renderer like PBRT or Mitsuba to create rendered images for each frame. You will of course have to set up the output format of your program in such a way that the renderer you’re using can read it.

• You could try writing your code in the scripting language of a 3D graphics program (Blender, Maya, etc.), or in a game engine like Unity or Unreal. In this case, make sure you create the vertices and polygons and define their motion through your own code, rather than using the built-in functionality of the software you’re using. Make sure the scripting language allows you to call a decent linear algebra library like Eigen or Numpy, as you’re going to need it.

Choose whichever strategy with which you feel confident that you will be able to extend it to more complex programs. If you don’t have significant experience with graphics programming, here’s a simple example program with OpenGL rendering in C++ that you can use as a starting point.