Example: 3D Room

The Tdemo example brings together many 3D capabilities in a single program. Tdemo offers first person perspective, with the viewer inside a square room with four texture-mapped walls. You can move the POV anywhere in the room through keyboard controls. Three texture-mapped cubes (similar to the cube in the TMcube example) spin around at fixed positions, each rotating about a different coordinate axis. Tdemo performs collision detection to prevent the viewer from walking through a wall, and it automatically adjusts the viewer's direction upon hitting a wall. No collision detection is performed for the three cubes, as we assume these are made of some strange polymer that lets you walk right inside the cube. A typical Tdemo scene is shown here:

Tdemo is a C++ program and uses an 800x600 high color virtual buffer to render each frame. It runs as a full screen application, setting the display resolution to 800x600 to match the virtual buffer size. By default, Tdemo will be a native Win32 program, but we can link it with Fastgraph's DirectX libraries to build a Direct3D version from the same source code through conditional compilation.

Tdemo uses two data files (Tdemo.ini and Tdemo.tmf) generated by FRED, the Fastgraph Rendering Editor. Tdemo.ini is a text file defining the viewer's initial position, the coordinates of the four walls in 3D world space, and what texture is assigned to each wall. Tdemo.tmf is a binary file containing the high color texture maps and their dimensions. The program's _LevelData::ReadFile() function reads the viewer's position and the wall information from Tdemo.ini and then calls _LevelData::ReadTextures() function to read the textures from Tdemo.tmf and assign them to the proper walls (as defined in Tdemo.ini). The three spinning cubes are created by three calls to _LevelData::AddItem(), which creates an _Item object representing the cube and then sequentially assigns different textures to each of its six faces.

The _Player::Motion() function processes keystrokes and updates the viewer's position (POV) accordingly. Pressing the up arrow key moves the POV forward; pressing the down arrow moves it backward (this involves movement in both the x and z directions). The left and right arrow keys rotate the POV y angle, allowing the viewer to look around the room. The PgUp and PgDn keys move the POV up or down.

Source code for Tdemo will not be presented here, but its C++ source code is included in the Tdemo subdirectory of the Fastgraph examples directory.

<< Prev

Next >>

Fastgraph Home Page


copyright 2001 Ted Gruber Software, Inc.