Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / FUiEffects_RendererDirectionalLight.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiEffects_RendererDirectionalLight.h
19  * @brief               This is the header file for the DirectionalLight class
20  */
21
22 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_DIRECTIONALLIGHT_H_
23 #define _FUI_EFFECTS_INTERNAL_RENDERER_DIRECTIONALLIGHT_H_
24
25 #include <FBaseSysLog.h>
26
27 #include <renderer/engine-model/FUiEffects_RendererEngineModelIntPropertyHolder.h>
28 #include <renderer/engine-model/FUiEffects_RendererEngineModelVector3fPropertyHolder.h>
29 #include <utils/FUiEffects_Utils.h>
30
31 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer
32 {
33
34 /**
35  * @class       DirectionalLight
36  * @brief       This class contains data for directional light in scene
37  *
38  */
39 class DirectionalLight
40 {
41 public:
42
43         /**
44          * Constructor
45          *
46          * @remark              Sets default values for members
47          */
48         DirectionalLight(void)
49         {
50                 result r = GetLastResult();
51                 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
52
53                 __direction = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
54                 __colorI = EngineModel::Vector3fPropertyHolderPtr(new (std::nothrow) EngineModel::Vector3fPropertyHolder);
55
56                 r = GetLastResult();
57                 SysTryReturnVoidResult(NID_UI_EFFECT, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
58                 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__direction) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
59                 SysTryReturnVoidResult(NID_UI_EFFECT, System::GetImpl(__colorI) != null, E_OUT_OF_MEMORY, _UiEffectError::OUT_OF_MEMORY);
60
61                 __direction->Set(Math::Vector3f(0.f, 0.f, -1.f));
62                 __color.set(1.f, 0.f, 0.f);
63                 __intensity = 1.f;
64                 __enabled = true;
65
66                 UpdateColorI();
67         }
68
69         /**
70         * Sets direction vector property
71         *
72         * @param [in]   direction                               New direction vector
73         *
74         * @return               void
75         */
76         void SetDirection(const Tizen::Ui::Effects::_Utils::Vec3f& direction)
77         {
78                 __direction->Set(Math::Vector3f(direction.x, direction.y, direction.z).Normalize());
79
80                 return;
81         }
82
83         /**
84         * Sets color property
85         *
86         * @param [in]   color                           New color value
87         *
88         * @return               void
89         */
90         void SetColor(const Tizen::Ui::Effects::_Utils::Vec3f& color)
91         {
92                 __color = color;
93                 UpdateColorI();
94
95                 return;
96         }
97
98         /**
99         * Sets intensity property
100         *
101         * @param [in]   intensity                               New intensity value
102         *
103         * @return               void
104         */
105         void SetIntensity(float intensity)
106         {
107                 __intensity = intensity;
108                 UpdateColorI();
109
110                 return;
111         }
112
113         /**
114         * Sets enabled value
115         *
116         * @param [in]   enabled                         New enabled value
117         *
118         * @return               void
119         */
120         void SetEnabled(bool enabled)
121         {
122                 __enabled = enabled;
123
124                 return;
125         }
126
127         /**
128         * Gets direction vector property
129         *
130         * @return               direction vector property
131         */
132         EngineModel::Vector3fPropertyHolderPtr GetDirectionHolder(void) const
133         {
134                 return __direction;
135         }
136
137         /**
138         * Gets color*intensity value property
139         *
140         * @return               color*intensity value property
141         */
142         EngineModel::Vector3fPropertyHolderPtr GetColorIHolder(void) const
143         {
144                 return __colorI;
145         }
146
147         /**
148         * Gets enabled value
149         *
150         * @return               enabled value
151         */
152         bool GetEnabled(void) const
153         {
154                 return __enabled;
155         }
156
157 private:
158
159         /**
160          * Hidden copy constructor
161          */
162         DirectionalLight(const DirectionalLight &rhs);
163
164
165         /**
166          * Hidden assignment operator
167          */
168         DirectionalLight& operator=(const DirectionalLight &rhs);
169
170         /**
171         * Sets colorI property which is premultiplied color x intensity for use in shader
172         *
173         * @return               void
174         */
175         void UpdateColorI(void)
176         {
177                 __colorI->Set(__color.x * __intensity, __color.y * __intensity, __color.z * __intensity);
178
179                 return;
180         }
181
182 private:
183         _Utils::Vec3f __color;
184         float __intensity;
185         bool __enabled;
186
187         EngineModel::Vector3fPropertyHolderPtr __direction;
188         EngineModel::Vector3fPropertyHolderPtr __colorI;                /**<  __color x __intensity */
189 }; // DirectionalLight
190
191 typedef System::SmartPtr<DirectionalLight> DirectionalLightPtr;
192
193 } } } } // Tizen::Ui::Effects::_EffectRenderer
194
195 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_DIRECTIONALLIGHT_H_