[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
2.9.6 Lighting sample
In contrast to the most of other programs, MathGL supports several (up to 10) light sources. Moreover, the color each of them can be different: white (this is usual), yellow, red, cyan, green and so on. The use of several light sources may be interesting for the highlighting of some peculiarities of the plot or just to make an amusing picture. Note, each light source can be switched on/off individually. The sample code is:
int sample(mglGraph *gr) { mglData a; mgls_prepare2d(&a); gr->Title("Several light sources"); gr->Rotate(50,60); gr->Light(true); gr->AddLight(1,mglPoint(0,1,0),'c'); gr->AddLight(2,mglPoint(1,0,0),'y'); gr->AddLight(3,mglPoint(0,-1,0),'m'); gr->Box(); gr->Surf(a,"h"); return 0; }

Additionally, you can use local light sources and set to use diffise reflection instead of specular one (by default) or both kinds.
int sample(mglGraph *gr) { // use Quality=6 because need lighting in placed int qual = gr->GetQuality(); gr->Light(true); gr->SetQuality(6); mglData a; mgls_prepare2d(&a); gr->SubPlot(2,2,0); gr->Title("Default"); gr->Rotate(50,60); gr->Box(); gr->Surf(a); gr->Line(mglPoint(-1,-0.7,1.7),mglPoint(-1,-0.7,0.7),"BA"); gr->AddLight(0,mglPoint(1,0,1),mglPoint(-2,-1,-1)); gr->SubPlot(2,2,1); gr->Title("Local"); gr->Rotate(50,60); gr->Box(); gr->Surf(a); gr->Line(mglPoint(1,0,1),mglPoint(-1,-1,0),"BAO"); gr->SetDiffuse(0); gr->SubPlot(2,2,2); gr->Title("no diffuse"); gr->Rotate(50,60); gr->Box(); gr->Surf(a); gr->Line(mglPoint(1,0,1),mglPoint(-1,-1,0),"BAO"); gr->SetDiffuse(0.5); gr->AddLight(0,mglPoint(1,0,1),mglPoint(-2,-1,-1),'w',0); gr->SubPlot(2,2,3); gr->Title("diffusive only"); gr->Rotate(50,60); gr->Box(); gr->Surf(a); gr->Line(mglPoint(1,0,1),mglPoint(-1,-1,0),"BAO"); gr->SetQuality(qual); }

This document was generated on March 21, 2014 using texi2html 5.0.