11.74 Sample ‘light

Example of light with different types.

MGL code:

light on:attachlight on
call 'prepare2d'
subplot 2 2 0:title 'Default':rotate 50 60:box:surf a
line -1 -0.7 1.7 -1 -0.7 0.7 'BA'

subplot 2 2 1:title 'Local':rotate 50 60
light 0 1 0 1 -2 -1 -1
line 1 0 1 -1 -1 0 'BAO':box:surf a

subplot 2 2 2:title 'no diffuse':rotate 50 60
diffuse 0
line 1 0 1 -1 -1 0 'BAO':box:surf a

subplot 2 2 3:title 'diffusive only':rotate 50 60
diffuse 0.5:light 0 1 0 1 -2 -1 -1 'w' 0
line 1 0 1 -1 -1 0 'BAO':box:surf a

C++ code:

void smgl_light(mglGraph *gr)	// local light sources
{
	mglData a;	mgls_prepare2d(&a);
	gr->Light(true);	gr->AttachLight(true);
	if(big==3)
	{	gr->Rotate(50,60);	gr->Box();	gr->Surf(a);	return;	}
	gr->SubPlot(2,2,0);	gr->Title("Default");	gr->Rotate(50,60);
	gr->Line(mglPoint(-1,-0.7,1.7),mglPoint(-1,-0.7,0.7),"BA");	gr->Box();	gr->Surf(a);
	gr->SubPlot(2,2,1);	gr->Title("Local");	gr->Rotate(50,60);
	gr->AddLight(0,mglPoint(1,0,1),mglPoint(-2,-1,-1));
	gr->Line(mglPoint(1,0,1),mglPoint(-1,-1,0),"BAO");	gr->Box();	gr->Surf(a);
	gr->SubPlot(2,2,2);	gr->Title("no diffuse");	gr->Rotate(50,60);
	gr->SetDiffuse(0);
	gr->Line(mglPoint(1,0,1),mglPoint(-1,-1,0),"BAO");	gr->Box();	gr->Surf(a);
	gr->SubPlot(2,2,3);	gr->Title("diffusive only");	gr->Rotate(50,60);
	gr->SetDiffuse(0.5);
	gr->AddLight(0,mglPoint(1,0,1),mglPoint(-2,-1,-1),'w',0);
	gr->Line(mglPoint(1,0,1),mglPoint(-1,-1,0),"BAO");	gr->Box();	gr->Surf(a);
}

Sample light