From: Tom Robinson Date: Thu, 13 Oct 2016 09:49:07 +0000 (+0100) Subject: VR: Vr constants in one file + IPD changed to use existing stereobase X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ad1b2c03d8c2b27fa7a8a4841b7305bb7ff511a6;p=platform%2Fcore%2Fuifw%2Fdali-core.git VR: Vr constants in one file + IPD changed to use existing stereobase Change-Id: Ic6267ab6b0642e4e8ac5a1f84a4477637a353d56 --- diff --git a/dali/integration-api/file.list b/dali/integration-api/file.list index da95736..d2f21ef 100644 --- a/dali/integration-api/file.list +++ b/dali/integration-api/file.list @@ -44,7 +44,8 @@ platform_abstraction_header_files = \ $(platform_abstraction_src_dir)/platform-abstraction.h \ $(platform_abstraction_src_dir)/system-overlay.h \ $(platform_abstraction_src_dir)/lockless-buffer.h \ - $(platform_abstraction_src_dir)/vr-engine.h + $(platform_abstraction_src_dir)/vr-engine.h \ + $(platform_abstraction_src_dir)/vr-defaults.h platform_abstraction_events_header_files = \ $(platform_abstraction_src_dir)/events/event.h \ diff --git a/dali/integration-api/vr-defaults.h b/dali/integration-api/vr-defaults.h new file mode 100644 index 0000000..dcf625c --- /dev/null +++ b/dali/integration-api/vr-defaults.h @@ -0,0 +1,59 @@ +#ifndef DALI_INTERNAL_VR_DEFAULTS_H +#define DALI_INTERNAL_VR_DEFAULTS_H + +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Integration +{ + +namespace Vr +{ + + +// These dimensions must match those used by the Tizen VR engine. +// TODO: Get these from the Tizen VR engine when such an API is implemented. +const Viewport DEFAULT_VR_VIEWPORT_DIMENSIONS( 0, 0, 1024, 1024 ); + +// todor doxy + +// Interpupillary Distance is the distance between the center of the eyes, in meters. +const float DEFAULT_VR_INTERPUPILLARY_DISTANCE_METERS( 0.0635f ); + +// todor doxy // todor wrong fov? ( 96.0f ) +const float DEFAULT_VR_FIELD_OF_VIEW_DEGREES( 106.0f ); + +// todor doxy +const float DEFAULT_VR_NEAR_PLANE_METERS( 0.1f ); + +// todor doxy +const float DEFAULT_VR_FAR_PLANE_METERS( 300.0f ); + + +} // Vr + +} // Integration + +} // Dali + +#endif // DALI_INTERNAL_VR_DEFAULTS_H diff --git a/dali/integration-api/vr-engine.h b/dali/integration-api/vr-engine.h index 71215de..e36a94d 100644 --- a/dali/integration-api/vr-engine.h +++ b/dali/integration-api/vr-engine.h @@ -53,6 +53,7 @@ class VrEngine { public: + //todor move to vr-defaults? struct Eye { enum Type @@ -118,7 +119,6 @@ public: } virtual bool Initialize( Vr::VrEngineInitializeParams* initializeParams ) = 0; - virtual void SetEnabled( bool enabled ) = 0; virtual void Start() = 0; virtual void Stop() = 0; virtual void PreRender() = 0; diff --git a/dali/internal/common/core-impl.cpp b/dali/internal/common/core-impl.cpp index ecaf292..6dda104 100644 --- a/dali/internal/common/core-impl.cpp +++ b/dali/internal/common/core-impl.cpp @@ -388,8 +388,6 @@ Integration::SystemOverlay& Core::GetSystemOverlay() void Core::SetViewMode( ViewMode viewMode ) { mStage->SetViewMode( viewMode ); - // If setting a VR ViewMode, enable VR also. - SetVrEnabled( viewMode == VR ); } ViewMode Core::GetViewMode() const @@ -407,11 +405,6 @@ float Core::GetStereoBase() const return mStage->GetStereoBase(); } -void Core::SetVrEnabled( bool enabled ) -{ - mVrManager->SetEnabled( enabled ); -} - StagePtr Core::GetCurrentStage() { return mStage.Get(); diff --git a/dali/internal/common/core-impl.h b/dali/internal/common/core-impl.h index e378465..88f63ff 100644 --- a/dali/internal/common/core-impl.h +++ b/dali/internal/common/core-impl.h @@ -197,11 +197,6 @@ public: */ float GetStereoBase() const; - /** - * @copydoc Dali::Integration::Core::SetVrEnabled() - */ - void SetVrEnabled( bool enabled ); - private: // for use by ThreadLocalStorage /** diff --git a/dali/internal/common/vr-manager-impl.cpp b/dali/internal/common/vr-manager-impl.cpp index 7b83076..a1c2547 100644 --- a/dali/internal/common/vr-manager-impl.cpp +++ b/dali/internal/common/vr-manager-impl.cpp @@ -19,6 +19,7 @@ #include // EXTERNAL INCLUDES +#include #include #include //todor @@ -30,25 +31,16 @@ namespace Dali namespace Internal { -namespace -{ - -// These dimensions must match those used by the Tizen VR engine. -// TODO: Get these from the Tizen VR engine when such an API is implemented. -const Rect DEFAULT_VR_VIEWPORT_DIMENSIONS( 0, 0, 1024, 1024 ); - -} // Anonymous namespace - VrManager::VrManager( Dali::Integration::VrEngine* vrEngine ) -: mViewportDimensions( DEFAULT_VR_VIEWPORT_DIMENSIONS ), +: mViewportDimensions( Dali::Integration::Vr::DEFAULT_VR_VIEWPORT_DIMENSIONS ), mVrEngine( vrEngine ), mHeadNode( NULL ), mEnabled( false ), mEngineInitialized( false ) { std::cout << "todor: ##################################### VRMANAGER CTOR" << std::endl; - //todor get enabled state FROM vrengine + // We get the enabled state from the VR Engine in adaptor. vrEngine->Get( Integration::VrEngine::VrProperty::ENABLED, &mEnabled ); } @@ -56,16 +48,6 @@ VrManager::~VrManager() { } -void VrManager::SetEnabled( bool enabled ) -{ - //todor delete -#if 0 - std::cout << "todor: --------------------- VrManager::SetEnabled" << std::endl; - mEnabled = enabled; - mVrEngine->SetEnabled( enabled ); -#endif -} - bool VrManager::IsEnabled() const { return mEnabled; diff --git a/dali/internal/common/vr-manager-impl.h b/dali/internal/common/vr-manager-impl.h index 403f216..b690880 100644 --- a/dali/internal/common/vr-manager-impl.h +++ b/dali/internal/common/vr-manager-impl.h @@ -26,6 +26,7 @@ class VrManager * @param[in] vrEngine The VR engine abstraction object */ VrManager( Dali::Integration::VrEngine* vrEngine ); + /** * @brief Destructor. */ @@ -34,11 +35,6 @@ class VrManager /** * @brief todor */ - void SetEnabled( bool enabled ); - - /** - * @brief todor - */ bool IsEnabled() const; /** diff --git a/dali/internal/event/common/stage-impl.cpp b/dali/internal/event/common/stage-impl.cpp index 3cb5078..0cdbef5 100644 --- a/dali/internal/event/common/stage-impl.cpp +++ b/dali/internal/event/common/stage-impl.cpp @@ -41,9 +41,11 @@ #include //TODOVR -#include #include +#include #include +//todor +#include using Dali::Internal::SceneGraph::Node; using namespace Dali::Integration::Vr; @@ -57,16 +59,13 @@ namespace Internal namespace { -//TODOVR +//TODOVR todor: share struct? enum Eye { LEFT, RIGHT }; -//TODOVR -const float DEFAULT_STEREO_BASE( 10.0f ); - // Signals const char* const SIGNAL_KEY_EVENT = "keyEvent"; @@ -341,6 +340,7 @@ void Stage::UpdateCameras() case STEREO_HORIZONTAL: { + //todor put old code back for stereo modes // Stereo mode with horizontal split is for landscape mode. That's the reason for the cameras being rotated // Top camera renders the scene as seen from the right eye and bottom camera as seen from left. @@ -371,11 +371,14 @@ void Stage::UpdateCameras() case VR: { const float pixelAspect = GetDpi().y / GetDpi().x; - float stereoBase( 0.05f ); - int L = LEFT; - int R = RIGHT; + + // Convert from millimeters to meters, and half so value is distance of one eye to center. + const float interpupillaryDistanceMeters = mStereoBase / 1000.0f; + const float eyeToCenterDistanceMeters = -( interpupillaryDistanceMeters * 0.5f ); + if( mSize.width > mSize.height ) { + //todor share code with working section below? // Stereo mode with horizontal split is for landscape mode. That's the reason for the cameras being rotated // Top camera renders the scene as seen from the right eye and bottom camera as seen from left. // Calculate separation in pixels along vertical axis ( mStereoBase is defined in millimetres ) @@ -390,6 +393,7 @@ void Stage::UpdateCameras() mStereoInfo[LEFT].camera->SetAspectRatio( cameraAspect ); mStereoInfo[LEFT].camera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS ); mStereoInfo[LEFT].renderTask.SetViewport( Viewport( 0, 0, viewPortWidth, mSize.height ) ); + mStereoInfo[RIGHT].camera->SetPerspectiveProjection( Size( sizeX, mSize.height ), Vector2::ZERO ); mStereoInfo[RIGHT].camera->SetAspectRatio( cameraAspect ); mStereoInfo[RIGHT].camera->SetOrientation( Dali::ANGLE_0, Vector3::ZAXIS ); @@ -397,71 +401,31 @@ void Stage::UpdateCameras() } else { -#if 0 // Portrait aspect - default to VR on device. // Precalculations: const float sizeY = mSize.x * pixelAspect; - const float viewPortHeight = mSize.y / 2.0f; - const float cameraAspect = pixelAspect * ( sizeY / viewPortHeight ); - const float near = 100.0f; - const float far = 5000.0f; - // TODOVR: Base this off actual FoV values (EG. 96 degrees for GearVR) - // Recalculate fov based on viewport size. - const float fov = Radian( Degree(60) );//std::atan( viewPortHeight / ( 2.0f * mSize.width ) ); - - mStereoInfo[LEFT].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2::ZERO ); - mStereoInfo[LEFT].camera->SetAspectRatio( cameraAspect ); - mStereoInfo[LEFT].camera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); - mStereoInfo[LEFT].camera->SetFieldOfView( fov ); - mStereoInfo[LEFT].renderTask.SetViewport( Viewport( 0, viewPortHeight, mSize.width, viewPortHeight ) ); - - mStereoInfo[RIGHT].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2::ZERO ); - mStereoInfo[RIGHT].camera->SetAspectRatio( cameraAspect ); - mStereoInfo[RIGHT].camera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); - mStereoInfo[RIGHT].camera->SetFieldOfView( fov ); - mStereoInfo[RIGHT].renderTask.SetViewport( Viewport( 0, 0, mSize.width, viewPortHeight ) ); + const float cameraAspect = pixelAspect * ( sizeY / ( mSize.y / 2.0f ) ); - mDefaultCamera->SetPosition( 0.0f, 100.0f ); -#endif + // Add the interpupillary distance to the near-plane minimum value. + const float nearPlane = Dali::Integration::Vr::DEFAULT_VR_NEAR_PLANE_METERS + interpupillaryDistanceMeters; + const float farPlane = Dali::Integration::Vr::DEFAULT_VR_FAR_PLANE_METERS; + const float fov = Radian( Degree( Dali::Integration::Vr::DEFAULT_VR_FIELD_OF_VIEW_DEGREES ) ); - // Portrait aspect - default to VR on device. - // Precalculations: - const float sizeY = mSize.x * pixelAspect; - const float viewPortHeight = mSize.y / 2.0f; - const float cameraAspect = pixelAspect * ( sizeY / viewPortHeight ); - - // TODOVR: Base this off actual FoV values (EG. 96 degrees for GearVR) - // Recalculate fov based on viewport size. - float fov = std::atan( viewPortHeight / ( 2.0f * mSize.width ) ); - const float far = 300.0f; - float IPD = 0.0635f; - stereoBase = -IPD * 0.5f; - const float near = IPD + 0.1f; - fov = Radian( Degree(106) ); - - mStereoInfo[L].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2( +stereoBase, 0.0f ) ); - //mStereoInfo[LEFT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2::ZERO ); - //mStereoInfo[LEFT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2( 0.0f, stereoBase ) ); - //mStereoInfo[LEFT].camera->SetAspectRatio( cameraAspect ); - mStereoInfo[L].camera->SetOrientation( Dali::ANGLE_90, Vector3::ZAXIS ); - //mStereoInfo[LEFT].camera->SetFieldOfView( fov ); - mStereoInfo[L].renderTask.SetViewport( Viewport( 0, 0, 1024, 1024 ) ); - - //mStereoInfo[RIGHT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2::ZERO ); - //mStereoInfo[RIGHT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2( 0.0, -stereoBase ) ); - mStereoInfo[R].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2( -stereoBase, 0.0f ) ); - //mStereoInfo[RIGHT].camera->SetAspectRatio( cameraAspect ); - mStereoInfo[R].camera->SetOrientation( Dali::ANGLE_90, Vector3::ZAXIS ); - //mStereoInfo[RIGHT].camera->SetFieldOfView( fov ); - mStereoInfo[R].renderTask.SetViewport( Viewport( 0, 0, 1024, 1024 ) ); + mStereoInfo[LEFT].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, nearPlane, farPlane, Vector2( +eyeToCenterDistanceMeters, 0.0f ) ); + mStereoInfo[LEFT].camera->SetOrientation( Dali::ANGLE_90, Vector3::ZAXIS ); + mStereoInfo[LEFT].renderTask.SetViewport( Dali::Integration::Vr::DEFAULT_VR_VIEWPORT_DIMENSIONS ); + mStereoInfo[RIGHT].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, nearPlane, farPlane, Vector2( -eyeToCenterDistanceMeters, 0.0f ) ); + mStereoInfo[RIGHT].camera->SetOrientation( Dali::ANGLE_90, Vector3::ZAXIS ); + mStereoInfo[RIGHT].renderTask.SetViewport( Dali::Integration::Vr::DEFAULT_VR_VIEWPORT_DIMENSIONS ); } - mStereoInfo[L].camera->SetType( Camera::VR_EYE_LEFT ); - mStereoInfo[R].camera->SetType( Camera::VR_EYE_RIGHT ); // Same settings regardless of orientation: - mStereoInfo[L].camera->SetPosition( Vector3( 0.0f, -stereoBase, 0.0f ) ); - mStereoInfo[R].camera->SetPosition( Vector3( 0.0f, +stereoBase, 0.0f ) ); + mStereoInfo[LEFT].camera->SetType( Camera::VR_EYE_LEFT ); + mStereoInfo[LEFT].camera->SetPosition( Vector3( 0.0f, -eyeToCenterDistanceMeters, 0.0f ) ); + + mStereoInfo[RIGHT].camera->SetType( Camera::VR_EYE_RIGHT ); + mStereoInfo[RIGHT].camera->SetPosition( Vector3( 0.0f, +eyeToCenterDistanceMeters, 0.0f ) ); // Inform the VR manager of the Vr head node. Dali::Internal::SceneGraph::SetVrHeadNode( GetUpdateManager(), mDefaultCamera->GetCameraNode() ); @@ -512,20 +476,6 @@ void Stage::SetViewMode( ViewMode viewMode ) UpdateCameras(); } - - //TODOVR: Animate the look angle for testing. -#if 0 - Quaternion q = mDefaultCamera->GetCurrentOrientation(); - float duration = 3.0f; - mCamAnim = Dali::Animation::New( duration ); - Dali::CameraActor a = Dali::CameraActor( ( mDefaultCamera.Get() ) ); - float lookAngle = 20.0f; - mDefaultCamera->SetOrientation( Degree( ( 180.0f - ( lookAngle / 2.0f ) ) ), Vector3::YAXIS ); - mCamAnim.AnimateBy( Dali::Property( a, Dali::Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( lookAngle ) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT, TimePeriod( 0.0f, duration / 2.0f ) ); - mCamAnim.AnimateBy( Dali::Property( a, Dali::Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( -lookAngle ) ), Vector3::YAXIS ), AlphaFunction::EASE_IN_OUT, TimePeriod( duration / 2.0f, duration / 2.0f ) ); - mCamAnim.SetLooping( true ); - mDefaultCamera->SetOrientation( Radian( Math::PI * 0.95f ), Vector3::YAXIS ); -#endif } ViewMode Stage::GetViewMode() const @@ -713,7 +663,7 @@ Stage::Stage( AnimationPlaylist& playlist, mSize(Vector2::ZERO), mBackgroundColor(Dali::Stage::DEFAULT_BACKGROUND_COLOR), mViewMode( MONO ), - mStereoBase( DEFAULT_STEREO_BASE ), + mStereoBase( Dali::Integration::Vr::DEFAULT_VR_INTERPUPILLARY_DISTANCE_METERS * 1000.0f ), mSystemOverlay(NULL) { } diff --git a/dali/internal/event/common/stage-impl.h b/dali/internal/event/common/stage-impl.h index 2daad0b..aa4e92a 100644 --- a/dali/internal/event/common/stage-impl.h +++ b/dali/internal/event/common/stage-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_STAGE_H__ -#define __DALI_INTERNAL_STAGE_H__ +#ifndef DALI_INTERNAL_STAGE_H +#define DALI_INTERNAL_STAGE_H /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -500,7 +500,7 @@ private: Dali::Stage::SceneCreatedSignalType mSceneCreatedSignal; - //VR + //VR todor delete! Constraint mVRGyroEyeConstraint; Dali::Animation mVRDefaultCameraAnimation; /// To keep camera update running and keep hitting constraint }; @@ -529,4 +529,4 @@ inline const Internal::Stage& GetImplementation(const Dali::Stage& stage) } // namespace Dali -#endif // __DALI_INTERNAL_STAGE_H__ +#endif // DALI_INTERNAL_STAGE_H diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index 101c22c..2ca1d9d 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -361,11 +361,6 @@ void UpdateManager::SetVrHeadNode( Node* node ) mImpl->vrManager.SetHeadNode( node ); } -void UpdateManager::SetVrEnabled( bool enabled ) -{ - mImpl->vrManager.SetEnabled( enabled ); -} - void UpdateManager::ConnectNode( Node* parent, Node* node ) { DALI_ASSERT_ALWAYS( NULL != parent ); diff --git a/dali/internal/update/manager/update-manager.h b/dali/internal/update/manager/update-manager.h index ad91e03..660bce0 100644 --- a/dali/internal/update/manager/update-manager.h +++ b/dali/internal/update/manager/update-manager.h @@ -161,12 +161,6 @@ public: void SetVrHeadNode( Node* node ); /** - * @brief Sets VR mode on or off. - * @param[in] enabled True to enable VR mode, false to turn VR off - */ - void SetVrEnabled( bool enabled ); - - /** * Connect a Node to the scene-graph. * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained. * @pre The node does not already have a parent. @@ -1308,16 +1302,6 @@ inline void SetVrHeadNode( UpdateManager& manager, Node& node ) new (slot) LocalType( &manager, &UpdateManager::SetVrHeadNode, &node ); } -inline void SetVrEnabled( UpdateManager& manager, bool enabled ) -{ - typedef MessageValue1< UpdateManager, bool > LocalType; - - // Reserve some memory inside the message queue - unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) ); - - // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &manager, &UpdateManager::SetVrEnabled, enabled ); -} } // namespace SceneGraph