Return to previous page | Return to menu | Go to next page


3-2. Setting the light source

Use the function “slLight” to set the light source in SGL. The light source function has only a direction vector (light source vector) that represents the direction of the light, and does not include light intensity or color information.

[void slLight (VECTOR light);]
Set the light source in SGL.
For the parameter, substitute a VECTOR type variable (light source vector) that indicates the direction of the ray.
Light intensity and color information are not included in the parameters.
In SGL, rays are defined as always being emitted from a specified direction vector.
Also, unless the light source calculation is turned on in the surface attribute of the object, the shadow caused by the light source is not reflected even if the light source is set (refer to "Chapter 7: Polygon surface attribute" for details).

The polygon color determines the polygon color from the angle of incidence of light on the surface.
The closer the incident angle is to the vertical, the brighter it is, and the closer to the horizontal, the darker the image is displayed. The negative vertical direction is the darkest.

Cautions when setting the light source

If various conversion operations such as scale are applied to the current matrix, the light source calculation may not be performed correctly.
This occurs because the user uses matrix operation to calculate the light source vector specified by the function “slLight”. Therefore, when setting the light source, it is necessary to initialize the current matrix.
Use the function “slPushUnitMatrix” or “slUnitMatrix” to initialize the current matrix.

[Bool slPushUnitMatrix (void)]

Reserves a unit matrix on the stack and makes it the current matrix.
The previous current matrix is ​​temporarily saved at a higher level in the stack.

[void slUnitMatrix (MATRIX mtptr)]
The matrix specified by the

parameter is used as the unit matrix.
Assign the specified MATRIX type variable to the parameter.
If “CURRENT” is specified for the parameter, the conversion target matrix becomes the current matrix, and the current matrix can be initialized.

For details of the current matrix and matrix function, refer to “Chapter 5: Matrix”.

The following list 3-1 shows the change in the shade of the cube polygon surface when the direction vector of the light source is changed one after another for a cube placed in space.

List 3-1 sample_3_2: Change of object plane due to light source movement

Flow 3-1 sample_3_2: Light source movement flowchart

Note: SGL library functions that appeared in this chapter

In this chapter, the functions in the following table were explained.

Table 3-1 SGL library functions that appeared in this chapter


Return to previous page | Return to menu | Go to next page