Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

3D computer graphics: Slide it, spin it, make it move -- transforming your virtual world

Learn how to make your virtual world satisfy even the toughest customer

  • Print
  • Feedback
Before I present new material, I'd like to briefly review the two topics I covered last month -- building a computer model and displaying it on the computer screen.

We learned we could build a skeletal copy of a real-world object composed solely of line segments, which allows us to capture the essential information about each object's shape -- the coordinates and the edges. We simply record the coordinates of each line segment's begin and end points in a table, embed that table in a program, and voilà, we have a model of the world inside a computer.

Once we've transformed the world into a computer model, we naturally want to view the scene the model represents. Last month I described one way to transform the model into something that could be viewed on a computer screen. We took the model data, discarded one dimension (the z coordinate, which represents depth), scaled the resulting data (so that it fit on the computer screen), and drew a line for each line segment described by the data. These steps allowed us to create what is called a wire-frame view of the model. We use this term because every object in the view looks like it is made only of wire -- that is, only the edges are visible.

If you'd like more detail on either of these topics, see last month's column 3D computer graphics, Part 1.

Changing the world

The applets I presented last month fell short in a number of areas. In particular, they were static. Although the applets were good at displaying an object, the user couldn't interact with the object or the portal's view of the object. To see the object in another position or orientation, the user would have to calculate the new coordinates of the corners by hand (a tedious, not to mention error-prone set of operations), and then edit and recompile the source code. Of course, this approach assumes that your average run-of-the-mill user could actually perform these tasks!

As it turns out, many of the things a user might want to do to a shape (for example, rotate the shape) are easily described arithmetically. And you guessed it -- computers are great at arithmetic.

Before I proceed, let me step aside for one brief moment and define position and orientation as they pertain to our three-dimensional model of the world.

Position versus orientation

An object's position is its location relative to some point of reference (in our case, that point is the origin). If the object's location relative to that point doesn't change, we say that the object hasn't changed position. Figure 1 illustrates what I mean. The two squares at A have the same position, while the two squares at B do not.

Figure 1: Position versus orientation

An object's orientation is harder to define, but easy to illustrate. So let me dispense with the words and show you what orientation is. Take another look at Figure 1. The two squares at B have the same orientation, while the two squares at A do not. That was simple, wasn't it?

Now let's consider two very basic transformations that computers happen to do well: translations and rotations.

  • Print
  • Feedback

Resources
  • Previous How-To Java articles