Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / common / src / game_share / dir_light_setup.cpp
blobffa7653475f85a57534d0de61f7386c7cb228ff6
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "stdpch.h"
22 #include "dir_light_setup.h"
23 #include "georges_helper.h"
24 #include "nel/georges/u_form_elm.h"
27 //-----------------------------------------------
28 CDirLightSetup::CDirLightSetup() :
29 Ambiant(0, 0, 0),
30 Diffuse(255, 255, 255),
31 Specular(0, 0, 0),
32 Direction(1.f, 0.f, 0.f)
36 //-----------------------------------------------
37 void CDirLightSetup::blend(const CDirLightSetup &setup0, const CDirLightSetup &setup1, float blendFactor)
39 uint uiFactor = (uint) (256.f * blendFactor);
40 Ambiant.blendFromui(setup0.Ambiant, setup1.Ambiant, uiFactor);
41 Diffuse.blendFromui(setup0.Diffuse, setup1.Diffuse, uiFactor);
42 Specular.blendFromui(setup0.Specular, setup1.Specular, uiFactor);
43 Direction = (blendFactor * setup0.Direction + (1.f - blendFactor) * setup1.Direction).normed();
46 //-----------------------------------------------
47 void CDirLightSetup::modulate(float level)
49 uint uiLevel = (uint) (256.f * level);
50 Ambiant.modulateFromui(Ambiant, uiLevel);
51 Diffuse.modulateFromui(Diffuse, uiLevel);
52 Specular.modulateFromui(Specular, uiLevel);
55 //-----------------------------------------------
56 bool CDirLightSetup::build(const NLGEORGES::UFormElm &item)
58 NLMISC::CRGBA amb, dif, spe;
59 NLMISC::CVector dir;
61 const NLGEORGES::UFormElm *pElt;
62 // Light Direction
63 if (item.getNodeByName (&pElt, ".Direction") && pElt)
65 if (!CGeorgesHelper::convert(dir, *pElt)) return false;
67 // Light Ambiant
68 if (item.getNodeByName (&pElt, ".Ambiant") && pElt)
70 if (!CGeorgesHelper::convert(amb, *pElt)) return false;
73 // Light Diffuse
74 if (item.getNodeByName (&pElt, ".Diffuse") && pElt)
76 if (!CGeorgesHelper::convert(dif, *pElt)) return false;
79 // Light Specular
80 if (item.getNodeByName (&pElt, ".Specular") && pElt)
82 if (!CGeorgesHelper::convert(spe, *pElt)) return false;
85 Ambiant = amb;
86 Diffuse = dif;
87 Specular = spe;
88 Direction = dir;
90 return true;