Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / runtime / FUiEffects_RuntimeDirectionalLight.cpp
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_RuntimeDirectionalLight.cpp
19  * @brief       This file contains an implementation of DirectionalLight class methods
20  *
21  */
22
23 #include <FBaseDataType.h>
24 #include <FUiEffects_RuntimeDirectionalLight.h>
25
26 using namespace Tizen::Ui::Effects::_Utils;
27 using namespace std;
28
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Runtime
30 {
31
32 DirectionalLight::DirectionalLight(const string& name)
33                                         : UnitLight(name)
34                                         , isDirectionChanged(false)
35                                         , __direction(0.f, 0.f, -1.f)
36 {
37
38 }
39
40 DirectionalLight::DirectionalLight(bool enabled,
41                                                                         const string& name,
42                                                                         const Vec3f& colour,
43                                                                         float intensity,
44                                                                         const Vec3f& direction)
45                                                                                 : UnitLight(enabled, name, colour, intensity)
46                                                                                 , isDirectionChanged(false)
47                                                                                 , __direction(direction)
48 {
49
50 }
51
52
53 DirectionalLight::~DirectionalLight(void)
54 {
55
56 }
57
58 DirectionalLight*
59 DirectionalLight::CreateDirectionalLight(const string& name)
60 {
61         DirectionalLight* pDirectionalLight = new (std::nothrow) DirectionalLight(name);
62         AddUnitLightToPool(pDirectionalLight);
63         return pDirectionalLight;
64 }
65
66 DirectionalLight*
67 DirectionalLight::CreateDirectionalLight(bool isEnabled,
68                                                                                 const string& name,
69                                                                                 const Vec3f& colour,
70                                                                                 float intensity,
71                                                                                 const Vec3f& direction)
72 {
73         DirectionalLight* pDirectionalLight = new (std::nothrow) DirectionalLight(isEnabled,
74                                                                                                                                                         name,
75                                                                                                                                                         colour,
76                                                                                                                                                         intensity,
77                                                                                                                                                         direction);
78         AddUnitLightToPool(pDirectionalLight);
79         return pDirectionalLight;
80 }
81
82 const Vec3f&
83 DirectionalLight::GetDirection(void) const
84 {
85         return __direction;
86 }
87
88 void
89 DirectionalLight::SetDirection(const Tizen::Ui::Effects::_Utils::Vec3f& direction)
90 {
91         SetDirection(direction.x, direction.y, direction.z);
92         return;
93 }
94
95 void
96 DirectionalLight::SetDirection(float x, float y, float z)
97 {
98         if (fabs(__direction.x - x) > EFFECT_EPSILONF
99                 || fabs(__direction.y - y) > EFFECT_EPSILONF
100                 || fabs(__direction.z - z) > EFFECT_EPSILONF)
101         {
102                 __direction.x = x;
103                 __direction.y = y;
104                 __direction.z = z;
105                 isDirectionChanged = true;
106                 isSomethingChanged = true;
107         }
108         return;
109 }
110
111 TypeUnitLight
112 DirectionalLight::GetType(void) const
113 {
114         return TYPE_UNIT_LIGHT_DIRECTIONAL;
115 }
116
117 void
118 DirectionalLight::ResetSigns(void)
119 {
120         UnitLight::ResetSigns();
121         isDirectionChanged = false;
122 }
123
124 } } } } // Tizen::Ui::Effects::_Runtime