From: seungho Date: Fri, 30 Sep 2022 11:36:35 +0000 (+0900) Subject: Rotate camera when window orientation is changed. X-Git-Tag: dali_2.1.43~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=9ebf1ed94cdd6cfed6f69d41948f8cf5efdfb473;hp=4aa0584cea3f755c3e1871932f06bc005033d906 Rotate camera when window orientation is changed. Change-Id: I90d0c99abc83479316f323ae198e62fbb0775dd6 Signed-off-by: seungho --- diff --git a/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp b/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp index 08afa17..2f3fbf3 100644 --- a/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp +++ b/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -55,12 +57,14 @@ 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)) +: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)), + mWindowOrientation(DEFAULT_ORIENTATION) { } @@ -188,7 +192,7 @@ void SceneView::UnregisterModel(Scene3D::Model model) void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor) { - mIBLResourceReady = false; + mIBLResourceReady = false; Texture diffuseTexture = Dali::Scene3D::Loader::LoadCubeMap(diffuseUrl); if(diffuseTexture) { @@ -252,12 +256,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(); } @@ -354,14 +371,14 @@ void SceneView::UpdateRenderTask() mRenderTask.SetCameraActor(mSelectedCamera); } - Vector3 size = Self().GetProperty(Dali::Actor::Property::SIZE); + Vector3 size = Self().GetProperty(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) { @@ -409,6 +426,26 @@ void SceneView::UpdateRenderTask() mTexture.Reset(); } } + + RotateCamera(); + } +} + +void SceneView::OnWindowResized(Window window, Window::WindowSize size) +{ + mWindowOrientation = DevelWindow::GetPhysicalOrientation(window); + RotateCamera(); +} + +void SceneView::RotateCamera() +{ + if(mUseFrameBuffer) + { + DevelCameraActor::RotateProjection(mSelectedCamera, DEFAULT_ORIENTATION); + } + else + { + DevelCameraActor::RotateProjection(mSelectedCamera, mWindowOrientation); } } diff --git a/dali-scene3d/internal/controls/scene-view/scene-view-impl.h b/dali-scene3d/internal/controls/scene-view/scene-view-impl.h index ddd7319..548bfee 100644 --- a/dali-scene3d/internal/controls/scene-view/scene-view-impl.h +++ b/dali-scene3d/internal/controls/scene-view/scene-view-impl.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -30,8 +31,8 @@ #include // INTERNAL INCLUDES -#include #include +#include namespace Dali { @@ -204,6 +205,16 @@ private: */ void UpdateRenderTask(); + /** + * @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; @@ -216,8 +227,8 @@ private: Dali::FrameBuffer mRenderTarget; Dali::Texture mTexture; Dali::RenderTask mRenderTask; - - Layer mRootLayer; + Layer mRootLayer; + int32_t mWindowOrientation; Dali::Texture mSpecularTexture; Dali::Texture mDiffuseTexture;