[Tizen] Rotate camera when screen orientation is changed. 41/282441/2
authorseungho <sbsh.baek@samsung.com>
Fri, 30 Sep 2022 11:36:35 +0000 (20:36 +0900)
committerseungho <sbsh.baek@samsung.com>
Tue, 4 Oct 2022 03:46:56 +0000 (12:46 +0900)
Change-Id: I90d0c99abc83479316f323ae198e62fbb0775dd6
Signed-off-by: seungho <sbsh.baek@samsung.com>
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.h

index f0d08c2..0c5b792 100644 (file)
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
 #include <dali-toolkit/public-api/image-loader/image-url.h>
 #include <dali-toolkit/public-api/image-loader/image.h>
+#include <dali/devel-api/actors/camera-actor-devel.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/common/stage.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/integration-api/adaptor-framework/adaptor.h>
 
 // INTERNAL INCLUDES
 #include <dali-scene3d/internal/controls/model/model-impl.h>
@@ -56,13 +58,15 @@ BaseHandle Create()
 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::SceneView, Toolkit::Control, Create);
 DALI_TYPE_REGISTRATION_END()
 
-Property::Index RENDERING_BUFFER = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
+Property::Index   RENDERING_BUFFER    = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
+constexpr int32_t DEFAULT_ORIENTATION = 0;
 
 } // anonymous namespace
 
 SceneView::SceneView()
 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
-  mIblLoadedCallback(nullptr)
+  mIblLoadedCallback(nullptr),
+  mScreenOrientation(DEFAULT_ORIENTATION)
 {
 }
 
@@ -201,9 +205,9 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
   if(!mIblLoadedCallback)
   {
     mIBLResourceReady = false;
-    mDiffuseIblUrl = diffuseUrl;
-    mSpecularIblUrl = specularUrl;
-    mIblScaleFactor = scaleFactor;
+    mDiffuseIblUrl    = diffuseUrl;
+    mSpecularIblUrl   = specularUrl;
+    mIblScaleFactor   = scaleFactor;
     // The callback manager takes the ownership of the callback object.
     mIblLoadedCallback = MakeCallback(this, &SceneView::OnLoadComplete);
     Adaptor::Get().AddIdle(mIblLoadedCallback, false);
@@ -250,12 +254,25 @@ void SceneView::OnSceneConnection(int depth)
 {
   UpdateRenderTask();
 
+  Window window = DevelWindow::Get(Self());
+  if(window)
+  {
+    window.ResizeSignal().Connect(this, &SceneView::OnWindowResized);
+  }
+
   Control::OnSceneConnection(depth);
 }
 
 void SceneView::OnSceneDisconnection()
 {
   mModels.clear();
+
+  Window window = DevelWindow::Get(Self());
+  if(window)
+  {
+    window.ResizeSignal().Disconnect(this, &SceneView::OnWindowResized);
+  }
+
   Control::OnSceneDisconnection();
 }
 
@@ -352,14 +369,14 @@ void SceneView::UpdateRenderTask()
       mRenderTask.SetCameraActor(mSelectedCamera);
     }
 
-    Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
+    Vector3     size        = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
     const float aspectRatio = size.width / size.height;
     mSelectedCamera.SetAspectRatio(aspectRatio);
-    const float halfHeight = mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE];
-    const float halfWidth = aspectRatio * halfHeight;
+    const float halfHeight                                              = mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE];
+    const float halfWidth                                               = aspectRatio * halfHeight;
     mSelectedCamera[Dali::CameraActor::Property::LEFT_PLANE_DISTANCE]   = -halfWidth;
     mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE]  = halfWidth;
-    mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE]    = halfHeight; // Top is +ve to keep consistency with orthographic values
+    mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE]    = halfHeight;  // Top is +ve to keep consistency with orthographic values
     mSelectedCamera[Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE] = -halfHeight; // Bottom is -ve to keep consistency with orthographic values
     if(mUseFrameBuffer)
     {
@@ -407,6 +424,26 @@ void SceneView::UpdateRenderTask()
         mTexture.Reset();
       }
     }
+
+    RotateCamera();
+  }
+}
+
+void SceneView::OnWindowResized(Window window, Window::WindowSize size)
+{
+  mScreenOrientation = DevelWindow::GetPhysicalOrientation(window);
+  RotateCamera();
+}
+
+void SceneView::RotateCamera()
+{
+  if(mUseFrameBuffer)
+  {
+    DevelCameraActor::RotateProjection(mSelectedCamera, DEFAULT_ORIENTATION);
+  }
+  else
+  {
+    DevelCameraActor::RotateProjection(mSelectedCamera, mScreenOrientation);
   }
 }
 
@@ -447,7 +484,7 @@ void SceneView::OnLoadComplete()
   if(!mIBLResourceReady)
   {
     LoadImageBasedLight();
-    mIBLResourceReady = true;
+    mIBLResourceReady  = true;
     mIblLoadedCallback = nullptr;
   }
 
index 4dfe593..8bb0f9f 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
+#include <dali/public-api/adaptor-framework/window.h>
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/object/weak-handle.h>
 #include <dali/public-api/render-tasks/render-task.h>
@@ -30,8 +31,8 @@
 #include <dali/public-api/rendering/texture.h>
 
 // INTERNAL INCLUDES
-#include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
 #include <dali-scene3d/public-api/controls/model/model.h>
+#include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
 
 namespace Dali
 {
@@ -214,6 +215,16 @@ private:
    */
   void OnLoadComplete();
 
+  /*
+   * @brief Callback that will be called when window is resized.
+   */
+  void OnWindowResized(Window window, Window::WindowSize size);
+
+  /**
+   * @brief Update camera's projection orientation according to the screen orientation.
+   */
+  void RotateCamera();
+
 private:
   Toolkit::Visual::Base mVisual;
 
@@ -230,6 +241,7 @@ private:
   CallbackBase* mIblLoadedCallback;
   std::string   mDiffuseIblUrl;
   std::string   mSpecularIblUrl;
+  int32_t       mScreenOrientation;
 
   Layer         mRootLayer;
   Dali::Texture mSpecularTexture;