Function:ss2sl
From S2PLOT
ss2sl
Set the entire lighting environment
Prototype
void ss2sl(COLOUR ambient, int nlights, XYZ *lightpos, COLOUR *lightcol, int worldcoords);
Description
Set the entire lighting environment. The nlights in the scene are at positions lightpos with colours lightcol, and ambient lighting colour. If worldcoords > 0 then the caller has given world coordinates, otherwise they are viewport-relative coordinates.
See Also
ns2i | Illumination. |
ns2vi | Illumination - vector input. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"
int main(int argc, char *argv[])
{
COLOUR ambient = { 0.1, 0.0, 0.1 }; /* Ambient colour */
int nlights = 1; /* 1 light */
XYZ *light; /* Positions of lights */
COLOUR *lcol; /* Colours of lights */
int wc = 1; /* Use world coordinates */
int i; /* Loop variable */
srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/?",argc, argv); /* Open the display */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
light = (XYZ *) calloc(nlights, sizeof(XYZ)); /* Allocate memory */
lcol = (COLOUR *)calloc(nlights, sizeof(COLOUR)); /* Allocate memory */
for (i=0;i<nlights;i++) {
light[i].x = drand48()*2.0 - 1.0; /* Random light position */
light[i].y = drand48()*2.0 - 1.0;
light[i].z = drand48()*2.0 - 1.0;
lcol[i].r = drand48(); /* Random colour */
lcol[i].g = 1.0;
lcol[i].b = drand48();
ns2vthpoint(light[i], lcol[i], 4); /* Draw point where light is */
}
ns2sphere(0.0,0.0,0.0, 0.3, 1.0,1.0,1.0); /* Draw a "white" sphere */
ss2sl(ambient, nlights, light, lcol, wc); /* Turn on the lights */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.