TUTORIAL NINE
TERRA FORM

The purpose of this program is to demonstrate how you can create a vast landscape with very few commands. This program also demonstrates fogging and camera control.

This tutorial program can be loaded directly into the editor by clicking SAMPLE09.DBA.

rem Load stone floor bitmap into image
LOAD BITMAP "floor.bmp",1
GET IMAGE 1,0,0,128,128
DELETE BITMAP 1

rem Activate manual syncronization and hide mouse
SYNC ON : HIDE MOUSE

rem Make a 3D landscape
MAKE MATRIX 1,10000.0,10000.0,25,25

rem Texture landscape
PREPARE MATRIX TEXTURE 1,1,1,1

rem Randomise landscape
RANDOMIZE MATRIX 1,300.0

rem Activate and distance fogging
FOG ON
FOG COLOR 0
FOG DISTANCE 5000

rem Begin loop
DO

rem Control camera turret
IF LEFTKEY()=1 THEN angle#=angle#-3.0
IF RIGHTKEY()=1 THEN angle#=angle#+3.0

rem Ensure angle stays within range
angle#=wrapvalue(angle#)

rem Update camera
YROTATE CAMERA angle#

rem Refresh screen
SYNC

rem End loop
LOOP

The first part of the program loads a bitmap offscreen and grabs the contents as an image. This image will later be used to texture the landscape. To create the landscape, a matrix is used. A matrix is a collection of grid squares that can be raised, lowered and textured at your command. The program creates a matrix ten thousands square units in size, subdivided into 625 separate squares(25x25). The matrix is then textured and randomized to create the effect of stone hills.

If your graphics card supports such a feature, fogging is activated and the distance is set to the clipping range of the system. Dark blue is applied as the fog color and is later used to clear the screen.

A special real number is used for the camera angle value, indicated by the hash(#) appended to the variable. The left and right arrow keys alter the value of the angle variable and later code ensures the angle variable wraps around when either the maximum or minimum value is exceeded.

The last part of the main loop updates the angle of the camera using the ROTATE CAMERA command. In order to maintain a steady speed, the program uses SYNC to refresh the screen.

Final Step : Things for you to do

1. Change the program to make the camera rotate faster
2. Change the program to make the color of the sky turn red
3. Change the program to Randomize the matrix when a key is pressed

You can skip to the next tutorial by selecting TUTORIAL TEN.