Saturday, December 02, 2006

From Wikipedia: Computer animation - Detailed examples and pseudocode


This excerpt explains the "magic" behind computer animation.

In 2D computer animation, moving objects are often referred to as "sprites.” A sprite is an image that has a location associated with it. The location of the sprite is changed slightly, between each displayed frame, to make the sprite appear to move. The following pseudocode makes a sprite move from left to right:

var int x := 0, y := screenHeight ÷ 2;
while x <>// draw on top of the background
x := x + 5 // move to the right

Modern (2001) computer animation uses different techniques to produce animations. Most frequently, sophisticated mathematics is used to manipulate complex three dimensional polygons, apply “textures”, lighting and other effects to the polygons and finally rendering the complete image. A sophisticated graphical user interface may be used to create the animation and arrange its choreography. Another technique called constructive solid geometry defines objects by conducting boolean operations on regular shapes, and has the advantage that animations may be accurately produced at any resolution.

Let's step through the rendering of a simple image of a room with flat wood walls with a grey pyramid in the center of the room. The pyramid will have a spotlight shining on it. Each wall, the floor and the ceiling is a simple polygon, in this case, a rectangle. Each corner of the rectangles is defined by three values referred to as X, Y and Z. X is how far left and right the point is. Y is how far up and down the point is, and Z is far in and out of the screen the point is. The wall nearest us would be defined by four points: (in the order x, y, z). Below is a representaion of how the wall is defined.

(0, 10, 0)                        (10, 10, 0)

(0,0,0) (10, 0, 0)

The far wall would be:

(0, 10, 20)                        (10, 10, 20)

(0, 0, 20) (10, 0, 20)

The pyramid is made up of five polygons: the rectangular base, and four triangular sides. To draw this image the computer uses math to calculate how to project this image, defined by three dimensional data, onto a two dimensional computer screen.

View full entry.

No comments: