X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Frender-tasks%2Fscene-graph-camera.cpp;h=7aca9cbe66e19b31ca03e167fa37555897ae67aa;hb=ac9e7e10baaadac207c0cb9221525fd49dbf5925;hp=56e6b9e5d209f4687661d3bfecf25db959998aa2;hpb=bdc9e04578363ff23d527ed8d3944aea9e303c09;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/render-tasks/scene-graph-camera.cpp b/dali/internal/update/render-tasks/scene-graph-camera.cpp index 56e6b9e..7aca9cb 100644 --- a/dali/internal/update/render-tasks/scene-graph-camera.cpp +++ b/dali/internal/update/render-tasks/scene-graph-camera.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -29,8 +29,8 @@ namespace // unnamed namespace { -const unsigned int UPDATE_COUNT = 2u; // Update projection or view matrix this many frames after a change -const unsigned int COPY_PREVIOUS_MATRIX = 1u; // Copy view or projection matrix from previous frame +const uint32_t UPDATE_COUNT = 2u; // Update projection or view matrix this many frames after a change +const uint32_t COPY_PREVIOUS_MATRIX = 1u; // Copy view or projection matrix from previous frame } namespace Dali @@ -45,6 +45,12 @@ namespace SceneGraph namespace { +template< typename T > +T Sign( T value ) +{ + return T( T(0) < value ) - T( value < T(0) ); +} + void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vector3& up) { Vector3 vZ = target - eye; @@ -59,7 +65,6 @@ void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vec result.SetInverseTransformComponents(vX, vY, vZ, eye); } - void Frustum(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis) { float deltaZ = far - near; @@ -91,13 +96,12 @@ void Frustum(Matrix& result, float left, float right, float bottom, float top, f m[12] = m[13] = m[15] = 0.0f; } -void Perspective(Matrix& result, float fovy, float aspect, float near, float far, bool invertYAxis, const Vector2& stereoBias ) +void Perspective(Matrix& result, float fovy, float aspect, float near, float far, bool invertYAxis ) { float frustumH = tanf( fovy * 0.5f ) * near; float frustumW = frustumH * aspect; - Vector2 bias = stereoBias * 0.5f; - Frustum(result, -(frustumW + bias.x), frustumW - bias.x, -(frustumH + bias.y), frustumH - bias.y, near, far, invertYAxis); + Frustum(result, -frustumW, frustumW, -frustumH, frustumH, near, far, invertYAxis); } void Orthographic(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis) @@ -139,7 +143,7 @@ void Orthographic(Matrix& result, float left, float right, float bottom, float t const Dali::Camera::Type Camera::DEFAULT_TYPE( Dali::Camera::FREE_LOOK ); const Dali::Camera::ProjectionMode Camera::DEFAULT_MODE( Dali::Camera::PERSPECTIVE_PROJECTION ); const bool Camera::DEFAULT_INVERT_Y_AXIS( false ); -const float Camera::DEFAULT_FIELD_OF_VIEW( 45.0f*(M_PI/180.0f) ); +const float Camera::DEFAULT_FIELD_OF_VIEW( 45.0f*(Math::PI/180.0f) ); const float Camera::DEFAULT_ASPECT_RATIO( 4.0f/3.0f ); const float Camera::DEFAULT_LEFT_CLIPPING_PLANE(-240.0f); const float Camera::DEFAULT_RIGHT_CLIPPING_PLANE(240.0f); @@ -147,13 +151,13 @@ const float Camera::DEFAULT_TOP_CLIPPING_PLANE(-400.0f); const float Camera::DEFAULT_BOTTOM_CLIPPING_PLANE(400.0f); const float Camera::DEFAULT_NEAR_CLIPPING_PLANE( 800.0f ); // default height of the screen const float Camera::DEFAULT_FAR_CLIPPING_PLANE( DEFAULT_NEAR_CLIPPING_PLANE + 2.f * DEFAULT_NEAR_CLIPPING_PLANE ); -const Vector2 Camera::DEFAULT_STEREO_BIAS( 0.0f, 0.0f ); const Vector3 Camera::DEFAULT_TARGET_POSITION( 0.0f, 0.0f, 0.0f ); Camera::Camera() : mUpdateViewFlag( UPDATE_COUNT ), mUpdateProjectionFlag( UPDATE_COUNT ), + mProjectionRotation( 0 ), mNode( NULL ), mType( DEFAULT_TYPE ), mProjectionMode( DEFAULT_MODE ), @@ -166,11 +170,11 @@ Camera::Camera() mBottomClippingPlane( DEFAULT_BOTTOM_CLIPPING_PLANE ), mNearClippingPlane( DEFAULT_NEAR_CLIPPING_PLANE ), mFarClippingPlane( DEFAULT_FAR_CLIPPING_PLANE ), - mStereoBias( DEFAULT_STEREO_BIAS ), mTargetPosition( DEFAULT_TARGET_POSITION ), mViewMatrix(), mProjectionMatrix(), - mInverseViewProjection( Matrix::IDENTITY ) + mInverseViewProjection( Matrix::IDENTITY ), + mFinalProjection( Matrix::IDENTITY ) { } @@ -217,12 +221,6 @@ void Camera::SetAspectRatio( float aspectRatio ) mUpdateProjectionFlag = UPDATE_COUNT; } -void Camera::SetStereoBias( const Vector2& stereoBias ) -{ - mStereoBias = stereoBias; - mUpdateProjectionFlag = UPDATE_COUNT; -} - void Camera::SetLeftClippingPlane( float leftClippingPlane ) { mLeftClippingPlane = leftClippingPlane; @@ -265,6 +263,12 @@ void Camera::SetTargetPosition( const Vector3& targetPosition ) mUpdateViewFlag = UPDATE_COUNT; } +void Camera::RotateProjection( int rotationAngle ) +{ + mProjectionRotation = rotationAngle; + mUpdateViewFlag = UPDATE_COUNT; +} + const Matrix& Camera::GetProjectionMatrix( BufferIndex bufferIndex ) const { return mProjectionMatrix[ bufferIndex ]; @@ -280,6 +284,11 @@ const Matrix& Camera::GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) return mInverseViewProjection[ bufferIndex ]; } +const Matrix& Camera::GetFinalProjectionMatrix( BufferIndex bufferIndex ) const +{ + return mFinalProjection[ bufferIndex ]; +} + const PropertyInputImpl* Camera::GetProjectionMatrix() const { return &mProjectionMatrix; @@ -297,7 +306,7 @@ void Camera::Update( BufferIndex updateBufferIndex ) { mUpdateViewFlag = UPDATE_COUNT; } - if( mNode->GetDirtyFlags() & VisibleFlag ) + if( mNode->GetDirtyFlags() & NodePropertyFlags::VISIBLE ) { // If the visibility changes, the projection matrix needs to be re-calculated. // It may happen the first time an actor is rendered it's rendered only once and becomes invisible, @@ -307,8 +316,8 @@ void Camera::Update( BufferIndex updateBufferIndex ) } // if either matrix changed, we need to recalculate the inverse matrix for hit testing to work - unsigned int viewUpdateCount = UpdateViewMatrix( updateBufferIndex ); - unsigned int projectionUpdateCount = UpdateProjection( updateBufferIndex ); + uint32_t viewUpdateCount = UpdateViewMatrix( updateBufferIndex ); + uint32_t projectionUpdateCount = UpdateProjection( updateBufferIndex ); // if model or view matrix changed we need to either recalculate the inverse VP or copy previous if( viewUpdateCount > COPY_PREVIOUS_MATRIX || projectionUpdateCount > COPY_PREVIOUS_MATRIX ) @@ -334,9 +343,9 @@ bool Camera::ViewMatrixUpdated() return 0u != mUpdateViewFlag; } -unsigned int Camera::UpdateViewMatrix( BufferIndex updateBufferIndex ) +uint32_t Camera::UpdateViewMatrix( BufferIndex updateBufferIndex ) { - unsigned int retval( mUpdateViewFlag ); + uint32_t retval( mUpdateViewFlag ); if( 0u != mUpdateViewFlag ) { if( COPY_PREVIOUS_MATRIX == mUpdateViewFlag ) @@ -424,7 +433,7 @@ void Camera::UpdateFrustum( BufferIndex updateBufferIndex, bool normalize ) if ( normalize ) { - for ( unsigned int i = 0; i < 6; ++i ) + for ( uint32_t i = 0; i < 6; ++i ) { // Normalize planes to ensure correct bounding distance checking Plane& plane = planes.mPlanes[ i ]; @@ -437,7 +446,7 @@ void Camera::UpdateFrustum( BufferIndex updateBufferIndex, bool normalize ) } else { - for ( unsigned int i = 0; i < 6; ++i ) + for ( uint32_t i = 0; i < 6; ++i ) { planes.mSign[i] = Vector3( Sign(planes.mPlanes[ i ].mNormal.x), Sign(planes.mPlanes[ i ].mNormal.y), Sign(planes.mPlanes[ i ].mNormal.z) ); } @@ -473,9 +482,9 @@ bool Camera::CheckAABBInFrustum( BufferIndex bufferIndex, const Vector3& origin, return true; } -unsigned int Camera::UpdateProjection( BufferIndex updateBufferIndex ) +uint32_t Camera::UpdateProjection( BufferIndex updateBufferIndex ) { - unsigned int retval( mUpdateProjectionFlag ); + uint32_t retval( mUpdateProjectionFlag ); // Early-exit if no update required if ( 0u != mUpdateProjectionFlag ) { @@ -496,8 +505,7 @@ unsigned int Camera::UpdateProjection( BufferIndex updateBufferIndex ) mAspectRatio, mNearClippingPlane, mFarClippingPlane, - mInvertYAxis, - mStereoBias ); + mInvertYAxis ); break; } case Dali::Camera::ORTHOGRAPHIC_PROJECTION: @@ -513,6 +521,38 @@ unsigned int Camera::UpdateProjection( BufferIndex updateBufferIndex ) } mProjectionMatrix.SetDirty( updateBufferIndex ); + + Matrix &finalProjection = mFinalProjection[ updateBufferIndex ]; + finalProjection.SetIdentity(); + + Quaternion rotationAngle; + switch( mProjectionRotation ) + { + case 90: + { + rotationAngle = Quaternion( Dali::ANGLE_90, Vector3::ZAXIS ); + break; + } + case 180: + { + rotationAngle = Quaternion( Dali::ANGLE_180, Vector3::ZAXIS ); + break; + } + case 270: + { + rotationAngle = Quaternion( Dali::ANGLE_270, Vector3::ZAXIS ); + break; + } + default: + rotationAngle = Quaternion( Dali::ANGLE_0, Vector3::ZAXIS ); + break; + } + + Matrix rotation; + rotation.SetIdentity(); + rotation.SetTransformComponents( Vector3( 1.0f, 1.0f, 1.0f ), rotationAngle, Vector3( 0.0f, 0.0f, 0.0f ) ); + + Matrix::Multiply( finalProjection, mProjectionMatrix.Get( updateBufferIndex ), rotation ); } --mUpdateProjectionFlag; }