April Grow and Julie Rej CS161 Winter 2011 Final Project: Yarn Animation Due Thursday, March 17 2011 README Documents: README: This document. Simple descriptions of the files in this project and any notes to graders. Includes: Documents, Run Instructions, Code Documentation, and Notes View in Notepad++ for best formatting! Program.cs: The generated file when you make an XNA game that initates the main game loop in Game1.cs Game1.cs: Also a generated file when you make an XNA game. However, it is populated with instatiations of the following .cs classes. It also calls update and draw on them in the main game loop so that information and commands can filter down to their necesary places. Camera.cs: The camera object that follows a left-hand system. It can swap between front and side view on the yarn, as well as panning left/right/up/down and zooming in/out. Physics.cs: Primarily Julie's creation of home-brewed yarn physics. If it is active, it organizes the control points of the curve based on both the current pivot point set and the movement the user acts upon the end point of the yarn. yarn.cs: A very complicated object that manages overall yarn commands, the yarn curve, and its cylinders. It handles appending control points to the curve object, as well as creating and defining yarn cylinders. yarnCurve.cs: Another complicated object that manages the yarn curve itself. It applies all of the curve blending functions and algorithms based on given control points, as well as the sine wave animation on the control points, and designating physics. It handles a lot of user input, as well, to select between what forces change the control points and by how much. yarnShell.cs: Made mostly of magical XNA drawing code, the yarn shell object creates a wire frame of the cylinder and applies transformations to it (specified in yarn.cs) to orient the shell in space. Instructions on How to Run: Running the program requires Visual Studio C# 2008 to be installed, as well as XNA 3.1. All controls were changed to work solely on keyboard input, so at least you no longer need an Xbox controller. Double clicking on the "Pattern.sln" file and pressing F6 (to build) and F5 (to debug) will compile and run the program. If we are able to figure it out, we may compile a .exe that may or may not work without VS C# and XNA. We will try though. Controls (THERE ARE A LOT!): // Activating Xbox Controller m Toggles whether the Xbox or Keyboard is used to move the control points For debugging purposes with the Xbox controller // Curve Selection: 1 Use B-Spline to create curvepoints 2 Use Nth degree Bezier curve to create curvepoints 3 Use Catmull-Rom to create curvepoints // Control Points +/= Increments forward along the yarn's control points. If physics is on, it changes the pivot point. If physics is off, it changes the control point the user can move. XNA recognizes each of these keys as a single press. Shift doesn't matter. -/_ Decrements backward along the yarn's control points. If physics is on, it changes the pivot point. If physics is off, it changes the control point the user can move. XNA recognizes each of these keys as a single press. Shift does not matter. w Move the selected control point up (Positive Y) a Move the selected control point left (Negative X or Z depending on the camera view) s Move the selected control point down (Negative Y) d Move the selected control point right (Positive X or Z depending on the camera view) Space Adds a new control point to the list Backspace Deletes a control point from the end of the list (if possible) // Physics q Toggles influence of physics forces on/off // Yarn Animation f Turns off all sine wave influence on the curve. Freezes the yarn in position if it is moving. v Turns on sine wave influence in the X and Y only (2D) c Turns on sine wave influence in the X, Y, and Z (3D) y/t Increases/decreases the Amplitude of the sine wave h/g Increases/decreases the wavelength of the sine wave. Will eventually cycle back around on itself. n/b Increases/decreases the rate/speed at which the sine wave goes up and down. // Orientation r Resets the curve points to a roughly equally spaced zig-zag pattern. Useful if physics or user movement of the control points makes them unwieldly. // Camera Up arrow Pans camera up Down arrow Pans camera down Right arrow Pans camera right Left arrow Pans camera left Right shift Zooms camera in Left shift Zooms camera out Enter Toggles between front and side view Code Documentation: (Of Key functions. Full comments can be seen in the code) // Curve yarnCurve.Update() Selects which curve to draw and distributes the points to the various algorithms accordingly. eval_Tbezier(), factorial(), and combonatorial() These functions together make the complete nth order Bezier algorithm that ends up being drawn using key "2" matrixBlendBezier() and eval_bezier() These functions pull together the bezier matrix found in the tech paper. However, it's not used because they require sets of non-tri-overlapping points (1-2-3-4, then 4-5-6-7, rather than 1-2-3-4, 2-3-4-5, etc). We left it in there for completionist's sake. matrixBlendBspline() and eval_spline() These functions pull together the Bspline matrix found in the tech paper. It is drawn when using the key "1" and is our prefered method of drawing curves for yarn. matrixBlendCatmull() and eval_Catmull() These functions pull together the Catmull-Rom matrix found in the tech paper. It is drawn using the key "3" and is the only curve that interpolates inner points. matrixBlendHermite() and eval_Hermite() These functions pull together the hermite matrix found in the tech paper. However, it is also not used because it requires sets of two points rather than three (1-2-3-4, then 3-4-5-6, rather than 2-3-4-5). We left it in the code for completionist's sake. // Procedural Animation oscilateP() and oscilatePD() Both of these wiggle the yarn based on Amplitude, Wavelength, and Rate variables. The simple P does it in just 2D, and PD does it in 3D using sin and cos sides of the sine wave function. // Physics Physics.tension_F() This function gathers hand-made pseudo-physics forces based on the position of the end point and the current pivot point. It determines how tight the yarn is pulled, and thus how far it will hang down. Physics.updateCurvature() Using the forces found from tension_F, it spaces the control points from the pivot point to the end of the yarn. It is balanced with a few magic numbers to make the yarn look nice, as a majority of the experimenting we did in this area was custom. See our tech paper for more details. Notes: - We spent a lot of time on collision detection, but because we could never get it to work properly (and because it's out of the scope of this class), we completely cut it out of the final submission. - If you stretch the yarn apart too much and strain the abilities of the cylinders, the curve seems to explode a bit. however, the curve will always reform itself if you don't try to break it too hard and give it a chance to form back up. - PSSST: Our paper at 2000 words just barely hit the end of 3 pages. Pang's estimation of length vs. word count was off by a bit.