Using Two Cameras

Normally when you watch television you sit back, relax, and let the show entertain you. While you’re sitting there relaxing, there’s a lot of hard work going on, especially in the TV director’s control room. Whether it’s a sporting event, a sitcom, the local news, or a soap opera, there are typically three or more cameras that are continuously being switched by the director.

In the following example, we will create two cameras around our cylinder and then switch to each one, using the HideEntity and ShowEntity commands. While the program is running, we’ll switch each camera as if we were big-time television directors!

We’ll make this demo07-02.bb. The first thing we’ll do is create two cameras:

; Create camera
camera1=CreateCamera()
PositionEntity camera1,0,5,5
RotateEntity camera1,90,0,0
camera2=CreateCamera()
PositionEntity camera2,0,0,0

If we ran the program right now, the view would be from camera2 because it was the last camera created, as seen in Figure 7.4.

Figure 7.4. The view would be from camera2 because it’s the last one created.


Now we have to create the code to control the program while it is running.

; The following code makes our program run
While Not KeyDown( 1 )
RenderWorld
If KeyHit(2) HideEntity camera2
If KeyHit(3) ShowEntity camera2
Flip
Wend
End

The following two lines of code are the ones that control the camera:

If KeyHit(ONE_KEY) HideEntity camera2
If KeyHit(TWO_KEY) ShowEntity camera2

The first line, If KeyHit(ONE_KEY) HideEntity camera2, says that if you press the number 1 on the keyboard, then the camera will be hidden. When the camera is hidden with the HideEntity command, the view will default to the other camera, camera1. To show camera2 again, we use the ShowEntity command by pressing the number 2 on the keyboard, as seen in Figure 7.5.

Figure 7.5. The demo07-02.bb program. When you press the numbers 1 and 2, the second camera is activated or deactivated.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.0.85