Scene definition

### 4.2.5 Scene definition

    // Sphere information.
    // Values are:
    // Center, <Radius, Reflection, 0>, Color, <phong_size, amount, 0>
    #declare Coord = array[5][4]
    { {<-1.05,0,4>, <1,.5,0>, <1,.5,.25>, <40, .8, 0>}
      {<1.05,0,4>, <1,.5,0>, <.5,1,.5>, <40, .8, 0>}
      {<0,-3,5>, <2,.5,0>, <.25,.5,1>, <30, .4, 0>}
      {<-1,2.3,9>, <2,.5,0>, <.5,.3,.1>, <30, .4, 0>}
      {<1.3,2.6,9>, <1.8,.5,0>, <.1,.3,.5>, <30, .4, 0>}
    }

    // Light source directions and colors:
    #declare LVect = array[3][2]
    { {<-1, 0, -.5>, <.8,.4,.1>}
      {<1, 1, -.5>, <1,1,1>}
      {<0,1,0>, <.1,.2,.5>}
    }

Here we use a bit more complex declarations: Array declarations.

In fact, they are even more complex than simple arrays, as we are declaring two-dimensional arrays.

A simple one-dimensional array can be declared like:

    #declare MyArray = array[4] { 1, 2, 3, 4 }

and then values can be read from inside it with for example: `MyArray[2]` (which will return `3` in this case as the indexing starts from 0, ie. the index 0 gets the first value in the array).

A two-dimensional array can be thought as an array containing arrays. That is, if you say `array[3][2]`, that means "an array which has 3 elements; each one of those elements is an array with 2 elements". When you want to read a value from it, for example `MyArray[1][3]`, you can think about it as "get the fourth value from the second array" (as indexing starts from 0, then the index value 3 actually means "fourth value").

Note: although you can put almost anything inside an array (floats, vectors, objects and so on) you can only put one type of things inside an array. That is, you can't mix float values and objects inside the same array. (One nice feature is that all POV-Ray objects are considered equivalent, which means that an object array can contain any objects inside it.)

What we are doing here is to define the information for our spheres and light sources. The first array (called `Coord`) defines the information for the spheres and the second (`LVect`) defines the light sources.

For spheres we define their center as the first vector. The second vector has both the radius of the sphere and its reflection amount (which is equivalent to the `reflection` value in the `finish` block of an object). This is a trick we use to not to waste so much space, so we use two values of the same vector for defining two different things.

The third vector defines the color of the sphere and the fourth the specular component of the lighting (equivalent to `phong_size` and `phong` values in the `finish` block of an object).

The light source definition array contains direction vectors and colors. This means that the light sources are directional, that is, they just say which direction the light is coming from. It could have been equally easy to make point lights, though.

We will use the information inside these arrays later in order to raytrace the scene they define.