To go straight to the examples, click here
or scroll down to the bottom of this page.
The following describes my sample motion machine animation. My Motion machine
takes a file (or more specifically, an url) which describes the position
of the character as well as how to animate it.
The applet is curently set up to
animate when a user clicks and drags the mouse. I did this to initially
get a grasp on the speed and look of the animation but left it
because I liked the degree of control while experimenting. It would be fairly straightforward to make it animate with time.
A sample file for the animation on the next page
is this file. Here is a description of
how the file format works: (This is also contained in format.txt)
The instructions for this file-format are as follows:
-
The major functions are translate, rotate, and their variations
described below. translate takes the relative direction (local)
and the number of pixels to move (you can use fractions if desired).
rotate takes a direction (x,y,z) and a fraction which will
be a fraction of Pi (i.e., rotate x,.25 rotates about the relative
x-axis 0.25*Pi radians).
- To set the initial view, use the translate-initial and
rotate-initial functions, exactly like the rotate and translate above.
- To do rotation and translation animations, use rotate-animate and
translate-animate. They both take the direction, the "scheme" and
amount as above. There are currently six "schemes", which
describe the value for animation at a certain time. The schemes are
indexed from t=0 to t=9 currently as follows:
Scheme 0: 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0
Scheme 1: 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0
Scheme 2: 1.0, 2.0, 3.0, 4.0, 5.0, 5.5, 4.0, 3.0, 2.0, 1.0
Scheme 3: -10.0, -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.0, -2.0, -2.0
Scheme 4: 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0
Scheme 5: -1.0. 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0
By calling one of these schemes, the Motion Machine does a linear
interpolation through time, finds the value, and then multiples
the amount of rotation or translation you provide by that amount
in time. So, for schemes, 0, 1, 2, and 5, you end up getting
a periodic effect. I.e, rotate-animate x,1,.25 rotates around the
local x-axis by Pi/4 radians, starting at t=0 and as t goes to 1,
the amount of rotation decreases to zero, then back to 1.0 * Pi/4
at t=2, etc.
I hope to allow the user to specify what kind of schemes they
want to use either through the applet or simply this file. Plus,
it would be nice to give the user the chance to use a smoother,
non-linear interpolation. Currently, you can notice jumps in continuity of the animation,
something that would be fixed by longer, smoother, user-defined animation schemes (longer than time equal to 9 of course).
- drawBox takes the xlo,ylo,zlo,xhi,yhi,zhi coordinates and
draws the box accordingly. Since the java applet starts with the
top left corner as (0,0), it takes a while to get used to this.
- To push onto the stack use {, to pop, use }. For people
unfamiliar with data structures, this could be confusing,
so just leave the { and } where they are, or experiment
to make a new creature until it makes sense.
- Comments are done with // I used these to label the body
parts to make things easier.
I would like to have it set up so a user could upload a file
format to test their animation, but I could not get that working properly yet.
If you would like my code to play with, e-mail me.
Examples of the Animation Machine
Source Code for this program:
Parser.java - parses the figure file and returns
a java Vector
MMFile.java - looks at what Parser returns and
creates ths stack for the Motion Machine. Also includes preset time
arrays which are used by AnimationTime and MMFile for Lerping
VectorN.java - 3D transformations. Not the
same as Matrix3D.java from other programs; has a few extras as well as
some different multiplication (post vs. pre of matrices)
GenericApplet.java - Generic Buffered
Applet; Ken Perlin's which I borrowed/stole with permission
BoxFigureApplet.java - Main loop, uses
GenericApplet. Again adaped from something of Ken Perlin's
AnimationTime.java - Store presets for
time function. Lerping done by MMFile.java