Animation in OpenGL for Game Programming using SDL
Animation is the backbone of immersive experience in any game. This applies to both 2-D and 3-D games without exception. Hence, in order to create a seamless and immersive game environment, one must first understand the whys and wherefores of animation. One of the advantages that OpenGL has over other graphics and gaming toolkits is that in OpenGL, animation APIs are not low-level.
In other words, the APIs of OpenGL follow the nomenclature of trigonometry and motion used by physics and mathematics. It also means having a good base in math (especially co-ordinate geometry and trigonometry) and physics is also a requirement.
Therefore, in this discussion the first two sections will focus on the basic coordinate geometry essential for understanding animation APIs. In the third section, I will focus on the core APIs and techniques for animation and the four section will be used to demonstrate the basic animation in action. These are the issues to be discussed in this article.
2D/3D Prerequisites: the Basics
The basis of animation is performing either rotation or translation without stopping. In other words if either rotation or translation is done continuously, the resulting effect is animation. But before going into details of these operations, let me give you a quick overview of common terminology and concepts used in co-ordinate geometry. The most common terminology and concepts in 2-D as well as 3-D are:
Of these, the first three are the founding concepts of 2-D/3-D whereas the fourth is the basis of all the operations in 2 as well as 3-D effects. Let's have a look at them.
Origin is the center of the coordinate system in every Cartesian coordinate space. This is true for both 2-D as well as 3-D. It is a special location. If the coordinate space is thought to be a city with square boundaries, then the origin would be the center of the city.
As for axes, every 2-D Cartesian space has two straight lines that pass through the origin. Each line is known as axis and extends indefinitely in opposite directions. Both of them are opposite to each other. These two axes are named the x-axis (the horizontal axis) and the y-axis (the vertical axis).
When the coordinate system is extended to 3-D space, then a third axis comes into the picture, named the z-axis. One thing to keep in mind is that in 3-D space, a plane can be defined by a pair of axes. For example the plane defined by x-axis and y-axis is the xy-plane; it is perpendicular to the z-axis. Pictorially it looks like this:
The positive and negative position of an axis is based on the coordinate system, which I will be describing next.