Light Range

You can control how “strong” a light is by adjusting its range. The stronger the range is, the farther it will reach. In the next example, we’ll create a sphere that is far off in the distance and is lit by a spotlight. We’ll then change the light range to see how it affects our image. The code used to adjust the range is LightRange followed by the name of the light and the amount of range. Open the file called demo07-08.bb or enter this code:

;demo07-08.bb - Lights and Cameras
; ––––––––––––––––
Graphics3D 640,480
SetBuffer BackBuffer()

Const ESC_KEY = 1

; Create camera
camera=CreateCamera()

; Create a light
light=CreateLight(3)
LightRange light, 50


; This is the code for creating the sphere
sphere=CreateSphere()
PositionEntity sphere,0,0,9
ScaleEntity sphere, .5, .5, .5
EntityColor sphere, 0, 26, 125

; This following code deals with cameras and cylinders
While Not KeyDown(ESC_KEY)

    RenderWorld
    Flip
Wend
End

When you run the program, you should see a sphere, as in Figure 7.20.

Figure 7.20. This is what the object looks like without the LightRange command.


Now we are going to adjust the range of the light to make it stronger by adding this code in the Creating a light section. We’ll increase the range to 50.

; Creating a light
light=CreateLight()
LightRange light, 50

You’ll now see that the object appears brighter (see Figure 7.21) because we’ve increased its intensity using this code.

Figure 7.21. Adding LightRange to demo07-08.bb.


Note: Now You Try

Experiment with this code, adjusting the intensity (currently set at 50) to see the results you get by changing the range of a light.


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

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