2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/actor-attachments/camera-attachment-impl.h>
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/internal/update/manager/update-manager.h>
25 #include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
33 CameraAttachmentPtr CameraAttachment::New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode )
35 CameraAttachmentPtr attachment( new CameraAttachment( eventThreadServices ) );
37 // Transfer object ownership of scene-object to message
38 SceneGraph::CameraAttachment* sceneObject = CreateSceneObject();
39 AttachToNodeMessage( eventThreadServices.GetUpdateManager(), parentNode, sceneObject );
41 // Keep raw pointer for message passing
42 attachment->mSceneObject = sceneObject;
47 CameraAttachment::CameraAttachment( EventThreadServices& eventThreadServices )
48 : ActorAttachment( eventThreadServices ),
50 mType( SceneGraph::CameraAttachment::DEFAULT_TYPE ),
51 mProjectionMode( SceneGraph::CameraAttachment::DEFAULT_MODE ),
52 mInvertYAxis( SceneGraph::CameraAttachment::DEFAULT_INVERT_Y_AXIS ),
53 mFieldOfView( SceneGraph::CameraAttachment::DEFAULT_FIELD_OF_VIEW ),
54 mAspectRatio( SceneGraph::CameraAttachment::DEFAULT_ASPECT_RATIO ),
55 mLeftClippingPlane( SceneGraph::CameraAttachment::DEFAULT_LEFT_CLIPPING_PLANE ),
56 mRightClippingPlane( SceneGraph::CameraAttachment::DEFAULT_RIGHT_CLIPPING_PLANE ),
57 mTopClippingPlane( SceneGraph::CameraAttachment::DEFAULT_TOP_CLIPPING_PLANE ),
58 mBottomClippingPlane( SceneGraph::CameraAttachment::DEFAULT_BOTTOM_CLIPPING_PLANE ),
59 mNearClippingPlane( SceneGraph::CameraAttachment::DEFAULT_NEAR_CLIPPING_PLANE ),
60 mFarClippingPlane( SceneGraph::CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE ),
61 mStereoBias( SceneGraph::CameraAttachment::DEFAULT_STEREO_BIAS ),
62 mTargetPosition( SceneGraph::CameraAttachment::DEFAULT_TARGET_POSITION )
66 CameraAttachment::~CameraAttachment()
70 SceneGraph::CameraAttachment* CameraAttachment::CreateSceneObject()
72 return SceneGraph::CameraAttachment::New();
75 void CameraAttachment::SetType(Dali::Camera::Type type)
81 // sceneObject is being used in a separate thread; queue a message to set
82 SetTypeMessage( GetEventThreadServices(), *mSceneObject, type );
86 Dali::Camera::Type CameraAttachment::GetType() const
91 void CameraAttachment::SetProjectionMode(Dali::Camera::ProjectionMode projectionMode)
93 if( ! Equals(projectionMode, mProjectionMode) )
95 mProjectionMode = projectionMode;
97 // sceneObject is being used in a separate thread; queue a message to set
98 SetProjectionModeMessage( GetEventThreadServices(), *mSceneObject, projectionMode );
102 Dali::Camera::ProjectionMode CameraAttachment::GetProjectionMode() const
104 return mProjectionMode;
107 void CameraAttachment::SetFieldOfView( float fieldOfView )
109 if( ! Equals(fieldOfView, mFieldOfView) )
111 mFieldOfView = fieldOfView;
113 // sceneObject is being used in a separate thread; queue a message to set
114 SetFieldOfViewMessage( GetEventThreadServices(), *mSceneObject, fieldOfView );
118 float CameraAttachment::GetFieldOfView() const
123 void CameraAttachment::SetAspectRatio( float aspectRatio )
125 if( ! Equals(aspectRatio, mAspectRatio) )
127 mAspectRatio = aspectRatio;
129 // sceneObject is being used in a separate thread; queue a message to set
130 SetAspectRatioMessage( GetEventThreadServices(), *mSceneObject, aspectRatio );
134 float CameraAttachment::GetAspectRatio() const
139 void CameraAttachment::SetStereoBias(const Vector2& stereoBias)
141 if( ! Equals(stereoBias.x, mStereoBias.x ) || ! Equals(stereoBias.y, mStereoBias.y ) )
143 mStereoBias = stereoBias;
145 // sceneObject is being used in a separate thread; queue a message to set
146 SetStereoBiasMessage( GetEventThreadServices(), *mSceneObject, stereoBias );
150 Vector2 CameraAttachment::GetStereoBias() const
155 void CameraAttachment::SetLeftClippingPlane( float leftClippingPlane )
157 if( ! Equals(leftClippingPlane, mLeftClippingPlane ) )
159 mLeftClippingPlane = leftClippingPlane;
161 // sceneObject is being used in a separate thread; queue a message to set
162 SetLeftClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, leftClippingPlane );
166 float CameraAttachment::GetLeftClippingPlane() const
168 return mLeftClippingPlane;
171 void CameraAttachment::SetRightClippingPlane( float rightClippingPlane )
173 if( ! Equals(rightClippingPlane, mRightClippingPlane ) )
175 mRightClippingPlane = rightClippingPlane;
177 // sceneObject is being used in a separate thread; queue a message to set
178 SetRightClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, rightClippingPlane );
182 float CameraAttachment::GetRightClippingPlane() const
184 return mRightClippingPlane;
187 void CameraAttachment::SetTopClippingPlane( float topClippingPlane )
189 if( ! Equals(topClippingPlane, mTopClippingPlane ) )
191 mTopClippingPlane = topClippingPlane;
193 // sceneObject is being used in a separate thread; queue a message to set
194 SetTopClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, topClippingPlane );
198 float CameraAttachment::GetTopClippingPlane() const
200 return mTopClippingPlane;
203 void CameraAttachment::SetBottomClippingPlane( float bottomClippingPlane )
205 if( ! Equals(bottomClippingPlane, mBottomClippingPlane ) )
207 mBottomClippingPlane = bottomClippingPlane;
209 // sceneObject is being used in a separate thread; queue a message to set
210 SetBottomClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, bottomClippingPlane );
214 float CameraAttachment::GetBottomClippingPlane() const
216 return mBottomClippingPlane;
219 void CameraAttachment::SetNearClippingPlane( float nearClippingPlane )
221 if( ! Equals(nearClippingPlane, mNearClippingPlane ) )
223 mNearClippingPlane = nearClippingPlane;
225 // sceneObject is being used in a separate thread; queue a message to set
226 SetNearClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, nearClippingPlane );
230 float CameraAttachment::GetNearClippingPlane() const
232 return mNearClippingPlane;
235 void CameraAttachment::SetFarClippingPlane( float farClippingPlane )
237 if( ! Equals( farClippingPlane, mFarClippingPlane ) )
239 mFarClippingPlane = farClippingPlane;
241 // sceneObject is being used in a separate thread; queue a message to set
242 SetFarClippingPlaneMessage( GetEventThreadServices(), *mSceneObject, farClippingPlane );
246 float CameraAttachment::GetFarClippingPlane() const
248 return mFarClippingPlane;
251 void CameraAttachment::SetTargetPosition( Vector3 targetPosition )
253 if( targetPosition != mTargetPosition )
255 mTargetPosition = targetPosition;
257 SetTargetPositionMessage( GetEventThreadServices(), *mSceneObject, targetPosition );
261 Vector3 CameraAttachment::GetTargetPosition()
263 return mTargetPosition;
266 void CameraAttachment::SetInvertYAxis( bool invertYAxis )
268 if( invertYAxis != mInvertYAxis )
270 mInvertYAxis = invertYAxis;
272 // sceneObject is being used in a separate thread; queue a message to set
273 SetInvertYAxisMessage( GetEventThreadServices(), *mSceneObject, invertYAxis );
277 bool CameraAttachment::GetInvertYAxis() const
282 const Matrix& CameraAttachment::GetViewMatrix() const
284 const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
286 return sceneObject.GetViewMatrix( GetEventThreadServices().GetEventBufferIndex() );
289 const Matrix& CameraAttachment::GetProjectionMatrix() const
291 const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
293 return sceneObject.GetProjectionMatrix( GetEventThreadServices().GetEventBufferIndex() );
296 const Matrix& CameraAttachment::GetInverseViewProjectionMatrix() const
298 const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
300 return sceneObject.GetInverseViewProjectionMatrix( GetEventThreadServices().GetEventBufferIndex() );
303 const PropertyInputImpl* CameraAttachment::GetViewMatrixProperty() const
305 DALI_ASSERT_DEBUG( OnStage() );
307 const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
309 return sceneObject.GetViewMatrix();
312 const PropertyInputImpl* CameraAttachment::GetProjectionMatrixProperty() const
314 DALI_ASSERT_DEBUG( OnStage() );
316 const SceneGraph::CameraAttachment& sceneObject = *mSceneObject;
318 return sceneObject.GetProjectionMatrix();
321 void CameraAttachment::OnStageConnection()
326 void CameraAttachment::OnStageDisconnection()
331 } // namespace Internal