To actually see the terrain, you have two options. Either you can reposition your camera or you can change the location of your terrain. The following sections will cover both methods.
We need to change the position of the camera. The terrain begins at position 1 on the y axis, and in this case, our terrain extends to the position 512,1,59. Since the default camera is at position 0,0,0, we need to bring it up to 0,1,0 so that we can see the terrain. Add the following lines to the camera code to position it so that we can see the terrain:
; Create camera camera=CreateCamera() PositionEntity camera,0,1,0
If you run the program right now, you’ll see the beginning of the terrain we created. Not much of a terrain yet—just a gray box (see Figure 9.2).
Let’s add some controls so that we can navigate around the terrain with our arrow keys.
; This following code deals with cameras and terrain While Not KeyDown(ESC_KEY) If KeyDown(RIGHT_KEY) = True Then TurnEntity camera,0,-1,0 If KeyDown(LEFT_KEY) = True Then TurnEntity camera,0,1,0 If KeyDown(DOWN_KEY) = True Then MoveEntity camera,0,0,-0.05 If KeyDown(UP_KEY) = True Then MoveEntity camera,0,0,0.05 RenderWorld Flip Wend
Now run this program and use the arrow keys to move the camera around so that you can navigate around your terrain (see Figure 9.3).
Rather than changing the position of the camera in order to see the terrain, you can simply reposition the terrain. To do this, we make use of the PositionEntitycommand, as is done in demo09-02.bb (see Figure 9.4). All we have to do is add one line.
; Creating the terrain ground=CreateTerrain (512) PositionEntity ground, -500,-1,-500 ; This following code deals with cameras and terrain While Not KeyDown(ESC_KEY) If KeyDown(RIGHT_KEY)=True Then TurnEntity camera,0,-1,0 If KeyDown(LEFT_KEY)=True Then TurnEntity camera,0,1,0 If KeyDown(DOWN_KEY)=True Then MoveEntity camera,0,0,-0.05 If KeyDown(UP_KEY)=True Then MoveEntity camera,0,0,0.05 RenderWorld Flip Wend
We’ve lowered the plane so that it is now below the camera and can be seen. Here we chose a position of 0,-1,0, but you can choose any starting position that you’d like. In fact, try the same program above but replace the position of the terrain with different numbers to get the hang of it.
18.117.137.252