PovRay is not GPL, but its license makes it freely available ”even the source code. Installing PovRay is a simple matter, since it's available in many executable forms. Simply find one for your Linux distribution and install it.
So why PovRay? Is this a chapter about PovRay? Well, yes and no ”mostly yes. In order to understand 3D graphics, you will need a foundation to build on. I learned by using PovRay. That was a while ago, when there weren't too many quality tools to choose from. Today, you could pick up a fancy 3D application (modeler, renderer, animator) and go to town. But learning the basics is what it's all about, and I can't think of a better product than PovRay to do that. This won't be a PovRay tutorial, but more of an introduction to PovRay and the concepts of 3D art. Once you understand the concepts of 3D art, you'll be better prepared for the other tools available for 3D graphics production under Linux.
Working with PovRay is easy. Even though I'll go over a few PovRay features, it would be best if you read the PovRay documentation to get a better foundation. However, you can choose to simply follow along, but I can't promise I won't skip over or around some key items you would probably benefit from. Luckily, this stuff is pretty simple to grasp, so let's continue and see where this leads.
To start off, let's draw a simple box. Using a text editor, you will construct a scene file that describes how PovRay will render the scene. For example, you might draw a box by giving it the box command with some coordinates:
// Persistence of Vision Ray Tracer Scene Description File
// File: box_1.pov
// Auth: Steve Murphy
#include "colors.inc"
background { color White }
camera {
location <2, 2, -10>
look_at <2, 2, 0>
}
light_source { <5, 5, -15> color White}
box {
<0, 0, 0>, <5, 5, 5>
pigment { color Gray }
}
This is a scene file. It has a simple format and is loaded into the PovRay engine for rendering a scene. The scene, once rendered, is saved as a graphic image file, such as PNG. To generate the image file, type in the following command line:
povRay +i box_1.pov +o box_1.png +Fn16 +A0.1
The command line options for PovRay are numerous , but for this example we need only four:
+i box_1.pov | Specify the input scene file to read. |
+o box_1.png | Specify the output image file to write to. |
+Fn16 | Specify the format of the output file as a PNG file with 16 bits per pixel to represent color. |
+A0.1 | Anti-aliasing: remove the jaggies and smooth out the edges. |
The image produced is a very simple box ( Figure 23-1 ).
Did we really draw just a simple box with all that text? Well, of course not. With a simple adjustment to the camera position only, we are able to shed some more light on the scene, so to speak:
camera {
location <10, 10, -10>
look_at <1, 1, 2>
}
Make this small change to the scene file and then rerun the previous PovRay command line. It produces the result shown in Figure 23-2 . Oops! We actually drew a cube and not a box. However, all we did was move the camera around. We did not draw a different box. So what happened ? When you read the word box, think of a square packing box and not a simple square shape. You now have to begin thinking in three dimensions. Each coordinate in PovRay is a three-dimensional coordinate in space. The days of X,Y are out and X,Y,Z are in, my friend.
A good way to remember the coordinate system is to hold up your left hand like you are pointing a gun. Your thumb points straight up. This is the Y -axis. Your index finger points away from your chest. This is the Z -axis. Now uncurl your middle finger and point it perpendicular to your index finger (to your right). This is the X -axis. PovRay uses a left-hand coordinate system. OpenGL, on the other hand (pun in tended), uses a right-hand coordinate system.