Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / actor-attachments / camera-attachment-impl.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 // CLASS HEADER
18 #include <dali/internal/event/actor-attachments/camera-attachment-impl.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/internal/event/common/stage-impl.h>
23 #include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
24
25 using namespace std;
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 CameraAttachmentPtr CameraAttachment::New( const SceneGraph::Node& parentNode )
34 {
35   StagePtr stage = Stage::GetCurrent();
36
37   CameraAttachmentPtr attachment( new CameraAttachment( *stage ) );
38
39   // Transfer object ownership of scene-object to message
40   SceneGraph::CameraAttachment* sceneObject = CreateSceneObject();
41   AttachToNodeMessage( stage->GetUpdateManager(), parentNode, sceneObject );
42
43   // Keep raw pointer for message passing
44   attachment->mSceneObject = sceneObject;
45
46   return attachment;
47 }
48
49 CameraAttachment::CameraAttachment( Stage& stage )
50 : ActorAttachment( stage ),
51   mSceneObject( NULL ),
52   mType( SceneGraph::CameraAttachment::DEFAULT_TYPE ),
53   mProjectionMode( SceneGraph::CameraAttachment::DEFAULT_MODE ),
54   mInvertYAxis( SceneGraph::CameraAttachment::DEFAULT_INVERT_Y_AXIS ),
55   mFieldOfView( SceneGraph::CameraAttachment::DEFAULT_FIELD_OF_VIEW ),
56   mAspectRatio( SceneGraph::CameraAttachment::DEFAULT_ASPECT_RATIO ),
57   mStereoBias( SceneGraph::CameraAttachment::DEFAULT_STEREO_BIAS ),
58   mLeftClippingPlane( SceneGraph::CameraAttachment::DEFAULT_LEFT_CLIPPING_PLANE ),
59   mRightClippingPlane( SceneGraph::CameraAttachment::DEFAULT_RIGHT_CLIPPING_PLANE ),
60   mTopClippingPlane( SceneGraph::CameraAttachment::DEFAULT_TOP_CLIPPING_PLANE ),
61   mBottomClippingPlane( SceneGraph::CameraAttachment::DEFAULT_BOTTOM_CLIPPING_PLANE ),
62   mNearClippingPlane( SceneGraph::CameraAttachment::DEFAULT_NEAR_CLIPPING_PLANE ),
63   mFarClippingPlane( SceneGraph::CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE ),
64   mTargetPosition( SceneGraph::CameraAttachment::DEFAULT_TARGET_POSITION )
65 {
66 }
67
68 CameraAttachment::~CameraAttachment()
69 {
70 }
71
72 SceneGraph::CameraAttachment* CameraAttachment::CreateSceneObject()
73 {
74   return SceneGraph::CameraAttachment::New();
75 }
76
77 void CameraAttachment::SetType(Dali::Camera::Type type)
78 {
79   if( type != mType )
80   {
81     mType = type;
82
83     // sceneObject is being used in a separate thread; queue a message to set
84     SetTypeMessage( mStage->GetUpdateInterface(), *mSceneObject, type );
85   }
86 }
87
88 Dali::Camera::Type CameraAttachment::GetType() const
89 {
90   return mType;
91 }
92
93 void CameraAttachment::SetProjectionMode(Dali::Camera::ProjectionMode projectionMode)
94 {
95   if( ! Equals(projectionMode, mProjectionMode) )
96   {
97     mProjectionMode = projectionMode;
98
99     // sceneObject is being used in a separate thread; queue a message to set
100     SetProjectionModeMessage( mStage->GetUpdateInterface(), *mSceneObject, projectionMode );
101   }
102 }
103
104 Dali::Camera::ProjectionMode CameraAttachment::GetProjectionMode() const
105 {
106   return mProjectionMode;
107 }
108
109 void CameraAttachment::SetFieldOfView( float fieldOfView )
110 {
111   if( ! Equals(fieldOfView, mFieldOfView) )
112   {
113     mFieldOfView = fieldOfView;
114
115     // sceneObject is being used in a separate thread; queue a message to set
116     SetFieldOfViewMessage( mStage->GetUpdateInterface(), *mSceneObject, fieldOfView );
117   }
118 }
119
120 float CameraAttachment::GetFieldOfView() const
121 {
122   return mFieldOfView;
123 }
124
125 void CameraAttachment::SetAspectRatio( float aspectRatio )
126 {
127   if( ! Equals(aspectRatio, mAspectRatio) )
128   {
129     mAspectRatio = aspectRatio;
130
131     // sceneObject is being used in a separate thread; queue a message to set
132     SetAspectRatioMessage( mStage->GetUpdateInterface(), *mSceneObject, aspectRatio );
133   }
134 }
135
136 float CameraAttachment::GetAspectRatio() const
137 {
138   return mAspectRatio;
139 }
140
141 void CameraAttachment::SetStereoBias(float stereoBias)
142 {
143   if( ! Equals(stereoBias, mStereoBias) )
144   {
145     mStereoBias = stereoBias;
146
147     // sceneObject is being used in a separate thread; queue a message to set
148     SetStereoBiasMessage( mStage->GetUpdateInterface(), *mSceneObject, stereoBias );
149   }
150 }
151
152 float CameraAttachment::GetStereoBias(float stereoBias) const
153 {
154   return mStereoBias;
155 }
156
157 void CameraAttachment::SetLeftClippingPlane( float leftClippingPlane )
158 {
159   if( ! Equals(leftClippingPlane, mLeftClippingPlane ) )
160   {
161     mLeftClippingPlane = leftClippingPlane;
162
163     // sceneObject is being used in a separate thread; queue a message to set
164     SetLeftClippingPlaneMessage( mStage->GetUpdateInterface(), *mSceneObject, leftClippingPlane );
165   }
166 }
167
168 float CameraAttachment::GetLeftClippingPlane() const
169 {
170   return mLeftClippingPlane;
171 }
172
173 void CameraAttachment::SetRightClippingPlane( float rightClippingPlane )
174 {
175   if( ! Equals(rightClippingPlane, mRightClippingPlane ) )
176   {
177     mRightClippingPlane = rightClippingPlane;
178
179     // sceneObject is being used in a separate thread; queue a message to set
180     SetRightClippingPlaneMessage( mStage->GetUpdateInterface(), *mSceneObject, rightClippingPlane );
181   }
182 }
183
184 float CameraAttachment::GetRightClippingPlane() const
185 {
186   return mRightClippingPlane;
187 }
188
189 void CameraAttachment::SetTopClippingPlane( float topClippingPlane )
190 {
191   if( ! Equals(topClippingPlane, mTopClippingPlane ) )
192   {
193     mTopClippingPlane = topClippingPlane;
194
195     // sceneObject is being used in a separate thread; queue a message to set
196     SetTopClippingPlaneMessage( mStage->GetUpdateInterface(), *mSceneObject, topClippingPlane );
197   }
198 }
199
200 float CameraAttachment::GetTopClippingPlane() const
201 {
202   return mTopClippingPlane;
203 }
204
205 void CameraAttachment::SetBottomClippingPlane( float bottomClippingPlane )
206 {
207   if( ! Equals(bottomClippingPlane, mBottomClippingPlane ) )
208   {
209     mBottomClippingPlane = bottomClippingPlane;
210
211     // sceneObject is being used in a separate thread; queue a message to set
212     SetBottomClippingPlaneMessage( mStage->GetUpdateInterface(), *mSceneObject, bottomClippingPlane );
213   }
214 }
215
216 float CameraAttachment::GetBottomClippingPlane() const
217 {
218   return mBottomClippingPlane;
219 }
220
221 void CameraAttachment::SetNearClippingPlane( float nearClippingPlane )
222 {
223   if( ! Equals(nearClippingPlane, mNearClippingPlane ) )
224   {
225     mNearClippingPlane = nearClippingPlane;
226
227     // sceneObject is being used in a separate thread; queue a message to set
228     SetNearClippingPlaneMessage( mStage->GetUpdateInterface(), *mSceneObject, nearClippingPlane );
229   }
230 }
231
232 float CameraAttachment::GetNearClippingPlane() const
233 {
234   return mNearClippingPlane;
235 }
236
237 void CameraAttachment::SetFarClippingPlane( float farClippingPlane )
238 {
239   if( ! Equals( farClippingPlane, mFarClippingPlane ) )
240   {
241     mFarClippingPlane = farClippingPlane;
242
243     // sceneObject is being used in a separate thread; queue a message to set
244     SetFarClippingPlaneMessage( mStage->GetUpdateInterface(), *mSceneObject, farClippingPlane );
245   }
246 }
247
248 float CameraAttachment::GetFarClippingPlane() const
249 {
250   return mFarClippingPlane;
251 }
252
253 void CameraAttachment::SetTargetPosition( Vector3 targetPosition )
254 {
255   if( targetPosition != mTargetPosition )
256   {
257     mTargetPosition = targetPosition;
258
259     SetTargetPositionMessage( mStage->GetUpdateInterface(),  *mSceneObject, targetPosition );
260   }
261 }
262
263 Vector3 CameraAttachment::GetTargetPosition()
264 {
265   return mTargetPosition;
266 }
267
268 void CameraAttachment::SetInvertYAxis( bool invertYAxis )
269 {
270   if( invertYAxis != mInvertYAxis )
271   {
272     mInvertYAxis = invertYAxis;
273
274     // sceneObject is being used in a separate thread; queue a message to set
275     SetInvertYAxisMessage( mStage->GetUpdateInterface(), *mSceneObject, invertYAxis );
276   }
277 }
278
279 bool CameraAttachment::GetInvertYAxis() const
280 {
281   return mInvertYAxis;
282 }
283
284 const Matrix& CameraAttachment::GetViewMatrix() const
285 {
286   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
287
288   return sceneObject.GetViewMatrix( mStage->GetEventBufferIndex() );
289 }
290
291 const Matrix& CameraAttachment::GetProjectionMatrix() const
292 {
293   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
294
295   return sceneObject.GetProjectionMatrix( mStage->GetEventBufferIndex() );
296 }
297
298 const Matrix& CameraAttachment::GetInverseViewProjectionMatrix() const
299 {
300   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
301
302   return sceneObject.GetInverseViewProjectionMatrix( mStage->GetEventBufferIndex() );
303 }
304
305 const PropertyInputImpl* CameraAttachment::GetViewMatrixProperty() const
306 {
307   DALI_ASSERT_DEBUG( OnStage() );
308
309   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
310
311   return sceneObject.GetViewMatrix();
312 }
313
314 const PropertyInputImpl* CameraAttachment::GetProjectionMatrixProperty() const
315 {
316   DALI_ASSERT_DEBUG( OnStage() );
317
318   const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
319
320   return sceneObject.GetProjectionMatrix();
321 }
322
323 void CameraAttachment::OnStageConnection()
324 {
325   // do nothing
326 }
327
328 void CameraAttachment::OnStageDisconnection()
329 {
330   // do nothing
331 }
332
333 } // namespace Internal
334
335 } // namespace Dali