Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / renderer / engine-model / FUiEffects_RendererEngineModelNode.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 /**
19  * @file                FUiEffects_RendererEngineModelNode.cpp
20  * @brief               This file contains implementation of Node class
21  *
22  */
23
24 #include <renderer/engine-model/FUiEffects_RendererEngineModelNode.h>
25 #include <renderer/engine-model/FUiEffects_RendererEngineModelGroup.h>
26
27 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace EngineModel
28 {
29
30 Node::Node():
31         _pParent(null)
32 {
33         _relatedTransform.value.Identity();
34         _relatedTransform.invalid = false;
35
36         _worldTransform.value.Identity();
37         _worldTransform.invalid = false;
38
39         _boundBox.value.Identity();
40         _boundBox.invalid = false;
41         _boundBox.value.maximum.Set(1.0f, 1.0f, 1.0f);
42         _boundBox.value.minimum.Set(-1.0f, -1.0f, -1.0f);
43
44         _transformType = TransformationType::RELATED;
45         _transformMatrix.Identity();
46 }
47
48 Node::~Node(void)
49 {
50
51 }
52
53 void
54 Node::Visit(Visitor& visitor)
55 {
56         visitor.OnNode(*this);
57         return;
58 }
59
60 void
61 Node::ValidateLocal(void)
62 {
63         if ((_transformType == TransformationType::RELATED) || !_pParent)
64         {
65                 _relatedTransform.value = _transformMatrix;
66         }
67         else
68         {
69                 _relatedTransform.value = _pParent->GetWorld().GetInversed() * _transformMatrix;
70         }
71
72         _relatedTransform.invalid = false;
73         return;
74 }
75
76 void
77 Node::ValidateWorld(void)
78 {
79         if ((_transformType == TransformationType::WORLD) || !_pParent)
80         {
81                 _worldTransform.value = _transformMatrix;
82         }
83         else
84         {
85                 _worldTransform.value = _pParent->GetWorld() * _transformMatrix;
86         }
87
88         _worldTransform.invalid = false;
89         return;
90 }
91
92 void
93 Node::SetLocal(const Math::Matrix4f& arg)
94 {
95         _transformType = TransformationType::RELATED;
96         _transformMatrix = arg;
97         _relatedTransform.invalid = true;
98         _worldTransform.invalid = true;
99         TouchParentBoundBox();
100         return;
101 }
102
103 void
104 Node::SetWorld(const Math::Matrix4f& arg)
105 {
106         _transformType = TransformationType::WORLD;
107         _transformMatrix = arg;
108         _relatedTransform.invalid = true;
109         _worldTransform.invalid = true;
110         TouchParentBoundBox();
111         return;
112 }
113
114 void
115 Node::TouchParentBoundBox(void)
116 {
117         if (_pParent)
118         {
119                 _pParent->InvalidateBoundBox();
120         }
121         return;
122 }
123
124 const Math::Matrix4f&
125 Node::GetLocal(void)
126 {
127         if (_transformType == TransformationType::RELATED)
128         {
129                 return _transformMatrix;
130         }
131
132         if (_relatedTransform.invalid)
133         {
134                 ValidateLocal();
135         }
136         return _relatedTransform.value;
137 }
138
139 const Math::Matrix4f&
140 Node::GetWorld(void)
141 {
142         if (_transformType == TransformationType::WORLD)
143         {
144                 return _transformMatrix;
145         }
146
147         if (_worldTransform.invalid)
148         {
149                 ValidateWorld();
150         }
151         return _worldTransform.value;
152 }
153
154 const Aabb&
155 Node::GetBoundBox(void)
156 {
157         return _boundBox.value;
158 }
159
160 Aabb
161 Node::GetBoundBoxInParentSpace(void)
162 {
163         return GetBoundBox().GetTransformed(GetLocal());
164 }
165
166 bool
167 Node::AttachedToParent(Group* pParent)
168 {
169         if (null != _pParent)
170         {
171                 return false;
172         }
173         _pParent = pParent;
174
175         if (_transformType != TransformationType::WORLD)
176         {
177                 _worldTransform.invalid = true;
178         }
179
180         return true;
181 }
182
183 bool
184 Node::RemoveFromParent(Group* pParent)
185 {
186         if (pParent != _pParent)
187         {
188                 return false;
189         }
190
191         if (_transformType == TransformationType::WORLD)
192         {
193                 _relatedTransform.invalid = true;
194         }
195         else
196         {
197                 _worldTransform.invalid = true;
198         }
199
200         _pParent = null;
201         return true;
202 }
203
204 void
205 Node::ParentMoved(Group* pParent)
206 {
207         if (pParent != _pParent)
208         {
209                 return;
210         }
211
212         if (_transformType == TransformationType::WORLD)
213         {
214                 return;
215         }
216
217         _worldTransform.invalid = true;
218         return;
219 }
220
221 }}}}} //Tizen::Ui::Effects::_Renderer::EngineModel