Example: Incremental POV Functions

The Columns program draws a series of 2x2x10 rectangular columns, arranged in a grid 20 units apart. A single column, defined in object space, is drawn at each point in the grid. Through keyboard controls, you can move forward, backward, left, right, up, or down through the column field, and turn left, right, up, or down. Columns uses a fixed 600x480 window, with the upper 600x400 region representing the 3D viewport, and the lower 600x80 area for displaying the viewer's current position and direction, along with a summary of the keyboard controls. Each frame is rendered into a 600x400 virtual buffer and then displayed with fg_vbpaste(). We then use the upper 80 rows of this same virtual buffer to generate the information we'll display in the lower part of the window. The virtual buffer's color depth will be set to match the display color depth.

We define the initial POV through fg_3Dlookat(), with the viewer at (10,20,100) looking toward the 3D world space origin. When we change the POV in response to keyboard input, we use the incremental POV functions. For instance, when we press the up arrow to move forward, we call fg_3Dmoveforward(-5.0). Similarly, we call fg_3Dmoveforward(5.0) to move backward in response to the down arrow.

The program's CheckForMotion() function performs keystroke processing similar to the other 3D examples. We move the viewer in 5-unit increments, and rotate the viewer in 1° increments. Whenever the POV changes, we call the corresponding incremental POV function and then call the program's DrawColumns() function to render the scene at the new POV.

DrawColumns() renders 2,500 columns (arranged in a 50x50 grid), but it performs polygon culling with fg_3Dbehindviewer() to reduce the actual number of columns drawn per frame. The test point for culling is the column's center in the x-z plane. We use a culling tolerance of -1.0 because this is the x or z extent of a column from its center. This means we'll only eliminate columns that are completely invisible. Columns that are partially visible will be clipped as needed during 3D transformation. A column that isn't eliminated through polygon culling is positioned in the grid with fg_3Dmoveobject(), and each of its six faces are rendered with fg_3Dpolygonobject(). After rendering all 2,500 columns, DrawColumns() calls UpdateInfo() to display the new POV information. Both DrawColumns() and UpdateInfo() call fg_vbpaste() to display what they just drew.

C/C++ version

C++Builder version

Delphi version

Visual Basic version

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.