#include <dali/public-api/render-tasks/render-task-list.h>
//TODOVR
-#include <iostream>
#include <dali/integration-api/vr-engine.h>
+#include <dali/integration-api/vr-defaults.h>
#include <dali/internal/update/manager/update-manager.h>
+//todor
+#include <iostream>
using Dali::Internal::SceneGraph::Node;
using namespace Dali::Integration::Vr;
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";
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.
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 )
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 );
}
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() );
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
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)
{
}