From: Francisco Santos Date: Mon, 10 Mar 2014 10:50:52 +0000 (+0000) Subject: Changed view matrix calculation to fix related problems. X-Git-Tag: dali-2014-wk16-release~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F62%2F17762%2F1;p=platform%2Fcore%2Fuifw%2Fdali-core.git Changed view matrix calculation to fix related problems. Changed the view matrix to be the inverse of the Camera View matrix in the FREE_LOOK camera. Updated the LOOK_AT view matrix to match an equivalent FREE_LOOK camera. Updated sorting of renderables to work with the new view space. Updated shader viewport uniform translation to match new view space. Change-Id: Ideeacd1990ee4ebde715362e8006b0f2adebda91 Signed-off-by: Francisco Santos --- diff --git a/automated-tests/dali-test-suite/actors/utc-Dali-CameraActor.cpp b/automated-tests/dali-test-suite/actors/utc-Dali-CameraActor.cpp index 98a4ac1..26640cf 100644 --- a/automated-tests/dali-test-suite/actors/utc-Dali-CameraActor.cpp +++ b/automated-tests/dali-test-suite/actors/utc-Dali-CameraActor.cpp @@ -71,6 +71,9 @@ TEST_FUNCTION( UtcDaliCameraActorSetOrthographicProjection03, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliCameraActorReadProjectionMatrix, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliCameraActorAnimatedProperties, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliCameraActorPropertyIndices, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliCameraActorCheckLookAtAndFreeLookViews01, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliCameraActorCheckLookAtAndFreeLookViews02, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliCameraActorCheckLookAtAndFreeLookViews03, POSITIVE_TC_IDX ); namespace @@ -317,7 +320,7 @@ static void UtcDaliCameraActorDefaultProperties() application.SendNotification(); bool bValue; actor.GetProperty(CameraActor::INVERT_Y_AXIS).Get(bValue); - DALI_TEST_EQUALS(true, bValue, TEST_LOCATION); + DALI_TEST_EQUALS(false, bValue, TEST_LOCATION); std::vector indices ; indices.push_back(CameraActor::TYPE); @@ -532,15 +535,15 @@ static void UtcDaliCameraActorSetInvertYAxis() tet_infoline("Testing Dali::CameraActor Get/Set InvertYAxis"); CameraActor actor = CameraActor::New(); - DALI_TEST_EQUALS( actor.GetInvertYAxis(), true, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetInvertYAxis(), false, TEST_LOCATION ); - actor.SetInvertYAxis(false); + actor.SetInvertYAxis(true); - DALI_TEST_EQUALS( actor.GetInvertYAxis(), false, TEST_LOCATION ); + DALI_TEST_EQUALS( actor.GetInvertYAxis(), true, TEST_LOCATION ); bool bValue; actor.GetProperty(CameraActor::INVERT_Y_AXIS).Get(bValue); - DALI_TEST_EQUALS(false, bValue, TEST_LOCATION); + DALI_TEST_EQUALS(true, bValue, TEST_LOCATION); } static void UtcDaliCameraActorModelView() @@ -859,3 +862,184 @@ void UtcDaliCameraActorPropertyIndices() DALI_TEST_CHECK( indices.size() > basicActor.GetPropertyCount() ); DALI_TEST_EQUALS( indices.size(), camera.GetPropertyCount(), TEST_LOCATION ); } + +static void UtcDaliCameraActorCheckLookAtAndFreeLookViews01() +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + CameraActor freeLookCameraActor = CameraActor::New(stageSize); + freeLookCameraActor.SetParentOrigin(ParentOrigin::CENTER); + freeLookCameraActor.SetType(Camera::FREE_LOOK); + + Vector3 targetPosition(30.0f, 240.0f, -256.0f); + Actor target = Actor::New(); + target.SetParentOrigin(ParentOrigin::CENTER); + target.SetPosition(targetPosition); + + Constraint cameraOrientationConstraint = + Constraint::New ( Actor::ROTATION, + Source( target, Actor::WORLD_POSITION ), + Source( freeLookCameraActor, Actor::WORLD_POSITION ), + Source( target, Actor::WORLD_ROTATION ), + &LookAt ); + freeLookCameraActor.ApplyConstraint( cameraOrientationConstraint ); + + CameraActor lookAtCameraActor = CameraActor::New(stageSize); + lookAtCameraActor.SetType(Camera::LOOK_AT_TARGET); + lookAtCameraActor.SetTargetPosition(targetPosition); + lookAtCameraActor.SetParentOrigin(ParentOrigin::CENTER); + + stage.Add(target); + stage.Add(freeLookCameraActor); + stage.Add(lookAtCameraActor); + + // Create an arbitrary vector + for( float x=-1.0f; x<=1.0f; x+=0.1f ) + { + for( float y=-1.0f; y<1.0f; y+=0.1f ) + { + for( float z=-1.0f; z<1.0f; z+=0.1f ) + { + Vector3 position(x, y, z); + position.Normalize(); + position *= 200.0f; + + freeLookCameraActor.SetPosition(position); + lookAtCameraActor.SetPosition(position); + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + Matrix freeLookViewMatrix; + Matrix lookAtViewMatrix; + freeLookCameraActor.GetProperty(CameraActor::CameraActor::VIEW_MATRIX).Get(freeLookViewMatrix); + lookAtCameraActor.GetProperty(CameraActor::CameraActor::VIEW_MATRIX).Get(lookAtViewMatrix); + + DALI_TEST_EQUALS( freeLookViewMatrix, lookAtViewMatrix, 0.01, TEST_LOCATION ); + } + } + } +} + +static void UtcDaliCameraActorCheckLookAtAndFreeLookViews02() +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + CameraActor freeLookCameraActor = CameraActor::New(stageSize); + freeLookCameraActor.SetParentOrigin(ParentOrigin::CENTER); + freeLookCameraActor.SetType(Camera::FREE_LOOK); + + Vector3 targetPosition(30.0f, 240.0f, -256.0f); + Actor target = Actor::New(); + target.SetParentOrigin(ParentOrigin::CENTER); + target.SetPosition(targetPosition); + + Constraint cameraOrientationConstraint = + Constraint::New ( Actor::ROTATION, + Source( target, Actor::WORLD_POSITION ), + Source( freeLookCameraActor, Actor::WORLD_POSITION ), + Source( target, Actor::WORLD_ROTATION ), + &LookAt ); + freeLookCameraActor.ApplyConstraint( cameraOrientationConstraint ); + + CameraActor lookAtCameraActor = CameraActor::New(stageSize); + lookAtCameraActor.SetType(Camera::LOOK_AT_TARGET); + lookAtCameraActor.SetTargetPosition(targetPosition); + lookAtCameraActor.SetParentOrigin(ParentOrigin::CENTER); + + stage.Add(target); + stage.Add(freeLookCameraActor); + stage.Add(lookAtCameraActor); + + // Create an arbitrary vector + for( float x=-1.0f; x<=1.0f; x+=0.1f ) + { + for( float y=-1.0f; y<1.0f; y+=0.1f ) + { + for( float z=-1.0f; z<1.0f; z+=0.1f ) + { + Vector3 position(x, y, z); + position.Normalize(); + position *= 200.0f; + + freeLookCameraActor.SetPosition(position); + lookAtCameraActor.SetPosition(position); + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + Matrix freeLookViewMatrix; + Matrix lookAtViewMatrix; + freeLookCameraActor.GetProperty(CameraActor::CameraActor::VIEW_MATRIX).Get(freeLookViewMatrix); + lookAtCameraActor.GetProperty(CameraActor::CameraActor::VIEW_MATRIX).Get(lookAtViewMatrix); + + Matrix freeLookWorld = freeLookCameraActor.GetCurrentWorldMatrix(); + + Matrix freeLookTest(false); + Matrix::Multiply(freeLookTest, freeLookViewMatrix, freeLookWorld); + DALI_TEST_EQUALS( freeLookTest, Matrix::IDENTITY, 0.01f, TEST_LOCATION); + + DALI_TEST_EQUALS( freeLookViewMatrix, lookAtViewMatrix, 0.01, TEST_LOCATION ); + } + } + } +} + +static void UtcDaliCameraActorCheckLookAtAndFreeLookViews03() +{ + TestApplication application; + Stage stage = Stage::GetCurrent(); + Vector2 stageSize = stage.GetSize(); + + Vector3 targetPosition(Vector3::ZERO); + + CameraActor lookAtCameraActor = CameraActor::New(stageSize); + lookAtCameraActor.SetType(Camera::LOOK_AT_TARGET); + lookAtCameraActor.SetTargetPosition(targetPosition); + lookAtCameraActor.SetParentOrigin(ParentOrigin::CENTER); + stage.Add(lookAtCameraActor); + + Vector3 cameraOffset( 0.f, 0.f, 100.f ); + + CameraActor freeLookCameraActor = CameraActor::New(stageSize); + freeLookCameraActor.SetType(Camera::FREE_LOOK); + freeLookCameraActor.SetParentOrigin(ParentOrigin::CENTER); + + Quaternion cameraOrientation( Radian(Degree(180.f)), Vector3::YAXIS ); + freeLookCameraActor.SetPosition(cameraOffset); + freeLookCameraActor.SetRotation(cameraOrientation); + + Actor cameraAnchor = Actor::New(); + cameraAnchor.Add(lookAtCameraActor); + stage.Add(cameraAnchor); + + + for( float angle = 1.f; angle <= 180.f; angle += 1.f ) + { + Quaternion rotation(Radian(Degree(angle)), Vector3::YAXIS); + + lookAtCameraActor.SetPosition( rotation.Rotate( cameraOffset ) ); + cameraAnchor.SetRotation( rotation ); + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + + Matrix freeLookViewMatrix; + freeLookCameraActor.GetProperty(CameraActor::CameraActor::VIEW_MATRIX).Get(freeLookViewMatrix); + + Matrix freeLookWorld = freeLookCameraActor.GetCurrentWorldMatrix(); + + Matrix freeLookTest(false); + Matrix::Multiply( freeLookTest, freeLookViewMatrix, freeLookWorld); + DALI_TEST_EQUALS( freeLookTest, Matrix::IDENTITY, 0.01f, TEST_LOCATION); + } +} + diff --git a/automated-tests/dali-test-suite/effects/utc-Dali-ShaderEffect.cpp b/automated-tests/dali-test-suite/effects/utc-Dali-ShaderEffect.cpp index 792ee48..03d5054 100644 --- a/automated-tests/dali-test-suite/effects/utc-Dali-ShaderEffect.cpp +++ b/automated-tests/dali-test-suite/effects/utc-Dali-ShaderEffect.cpp @@ -535,6 +535,7 @@ static void UtcDaliShaderEffectMethodSetUniformViewport() Stage::GetCurrent().Add(actor); effect.SetUniform( "uVec2", Vector2( 0.0f, 0.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION ); + effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION ); application.SendNotification(); application.Render(); @@ -543,7 +544,10 @@ static void UtcDaliShaderEffectMethodSetUniformViewport() DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( - "uVec2", Vector2( -stageSize.x/2, stageSize.y/2 ) ) ); + "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) ); + DALI_TEST_CHECK( + application.GetGlAbstraction().CheckUniformValue( + "uVec2Dir", Vector2( -1.0f, 2.0f ) ) ); } static void UtcDaliShaderEffectMethodSetEffectImage() diff --git a/automated-tests/dali-test-suite/math/utc-Dali-Matrix.cpp b/automated-tests/dali-test-suite/math/utc-Dali-Matrix.cpp index 9e59cb0..9a692fe 100644 --- a/automated-tests/dali-test-suite/math/utc-Dali-Matrix.cpp +++ b/automated-tests/dali-test-suite/math/utc-Dali-Matrix.cpp @@ -67,7 +67,8 @@ TEST_FUNCTION( UtcDaliMatrixSetTranslation3, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixTranspose, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixOStreamOperator, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixMultiply, POSITIVE_TC_IDX ); -TEST_FUNCTION( UtcDaliMatrixOperatorMultiply, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliMatrixOperatorMultiply01, POSITIVE_TC_IDX ); +TEST_FUNCTION( UtcDaliMatrixOperatorMultiply02, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixOperatorEquals, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixOperatorNotEquals, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixGetTransformComponents01, POSITIVE_TC_IDX ); @@ -77,6 +78,7 @@ TEST_FUNCTION( UtcDaliMatrixSetInverseTransformComponent01, POSITIVE_TC_IDX ); TEST_FUNCTION( UtcDaliMatrixSetInverseTransformComponent02, POSITIVE_TC_IDX ); + // Called only once before first test is run. static void Startup() { @@ -528,8 +530,9 @@ static void UtcDaliMatrixMultiply() DALI_TEST_EQUALS(m2, r1, 0.01f, TEST_LOCATION); } -static void UtcDaliMatrixOperatorMultiply() +static void UtcDaliMatrixOperatorMultiply01() { + TestApplication application; Vector4 v1(2.0f, 5.0f, 4.0f, 0.0f); float els[] = {2.0f, 0.0f, 0.0f, 0.0f, @@ -543,6 +546,25 @@ static void UtcDaliMatrixOperatorMultiply() DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION); } +static void UtcDaliMatrixOperatorMultiply02() +{ + TestApplication application; + + Vector3 position ( 30.f, 40.f, 50.f); + + Matrix m1(false); + m1.SetIdentity(); + m1.SetTranslation(-position); + + Vector4 positionV4(position); + positionV4.w=1.0f; + Vector4 output = m1 * positionV4; + + output.w = 0.0f; + DALI_TEST_EQUALS(output, Vector4::ZERO, 0.01f, TEST_LOCATION); +} + + static void UtcDaliMatrixOperatorEquals() { Matrix m1 = Matrix::IDENTITY; diff --git a/capi/dali/public-api/shader-effects/shader-effect.h b/capi/dali/public-api/shader-effects/shader-effect.h index 962e90b..fa8a328 100644 --- a/capi/dali/public-api/shader-effects/shader-effect.h +++ b/capi/dali/public-api/shader-effects/shader-effect.h @@ -184,16 +184,16 @@ public: /** * Coordinate type of the shader uniform - * Viewport coordinates will be centered and inverted on the Y axis. Use this coordinate type - * if your are doing a transformation in view space. + * Viewport coordinate types will convert from viewport to view space. + * Use this coordinate type if your are doing a transformation in view space. * The texture coordinate type converts a value in actor local space to texture coodinates. * This is useful for pixel shaders and accounts for texture atlas. */ enum UniformCoordinateType { COORDINATE_TYPE_DEFAULT, ///< Default, No transformation to be applied - COORDINATE_TYPE_VIEWPORT_POSITION, ///< The uniform is a position vector in viewport coordinates, Needs to be converted to GL coordinates - COORDINATE_TYPE_VIEWPORT_DIRECTION, ///< The uniform is a directional vector in viewport coordinates, Needs to be converted to GL coordinates + COORDINATE_TYPE_VIEWPORT_POSITION, ///< The uniform is a position vector in viewport coordinates that needs to be converted to GL view space coordinates. + COORDINATE_TYPE_VIEWPORT_DIRECTION, ///< The uniform is a directional vector in viewport coordinates that needs to be converted to GL view space coordinates. COORDINATE_TYPE_TEXTURE_POSITION ///< The uniform is a position in texture coordinates. }; diff --git a/dali/internal/event/actors/camera-actor-impl.cpp b/dali/internal/event/actors/camera-actor-impl.cpp index 1936388..9015fde 100644 --- a/dali/internal/event/actors/camera-actor-impl.cpp +++ b/dali/internal/event/actors/camera-actor-impl.cpp @@ -152,7 +152,8 @@ void BuildOrthoPickingRay( const Matrix& viewMatrix, Vector4 cameraOrigin = invView * Vector4( 0.f, 0.f, 0.f, 1.f ); Vector4 nearPlaneOrigin = invView * Vector4( 0.0f, 0.0f, -nearPlaneDistance, 1.0f); - rayDir = (nearPlaneOrigin - cameraOrigin); + // Vector pointing from the camera to the near plane + rayDir = cameraOrigin - nearPlaneOrigin; rayOrigin -= rayDir; rayDir.Normalize(); rayDir.w = 1.0f; @@ -355,7 +356,10 @@ void CameraActor::SetOrthographicProjection( float left, float right, float top, SetProjectionMode(Dali::Camera::ORTHOGRAPHIC_PROJECTION); } -bool CameraActor::BuildPickingRay( const Vector2& screenCoordinates, const Viewport& viewport, Vector4& rayOrigin, Vector4& rayDirection ) +bool CameraActor::BuildPickingRay( const Vector2& screenCoordinates, + const Viewport& viewport, + Vector4& rayOrigin, + Vector4& rayDirection ) { bool success = true; if( GetProjectionMode() == Dali::Camera::PERSPECTIVE_PROJECTION ) @@ -382,9 +386,14 @@ bool CameraActor::BuildPickingRay( const Vector2& screenCoordinates, const Viewp } else { - // TODO someone who understands the math needs to optimise this version as well float nearPlaneDistance = GetNearClippingPlane(); - BuildOrthoPickingRay( GetViewMatrix(), GetProjectionMatrix(), viewport, screenCoordinates.x, screenCoordinates.y, rayOrigin, rayDirection, nearPlaneDistance ); + BuildOrthoPickingRay( GetViewMatrix(), + GetProjectionMatrix(), + viewport, screenCoordinates.x, + screenCoordinates.y, + rayOrigin, + rayDirection, + nearPlaneDistance ); } return success; diff --git a/dali/internal/event/actors/layer-impl.h b/dali/internal/event/actors/layer-impl.h index 7de886b..3ac048d 100644 --- a/dali/internal/event/actors/layer-impl.h +++ b/dali/internal/event/actors/layer-impl.h @@ -49,7 +49,7 @@ public: static float ZValue(const Vector3& position, float sortModifier) { // inlined so we avoid a function call when sorting renderers - return -position.z + sortModifier; + return position.z + sortModifier; } /** diff --git a/dali/internal/event/events/hit-test-algorithm-impl.cpp b/dali/internal/event/events/hit-test-algorithm-impl.cpp index d88a4ba..5077f70 100644 --- a/dali/internal/event/events/hit-test-algorithm-impl.cpp +++ b/dali/internal/event/events/hit-test-algorithm-impl.cpp @@ -322,7 +322,11 @@ bool HitTestRenderTask( LayerList& layers, const unsigned int sourceActorDepth( layer.GetDepth() ); CameraActor* cameraActor = renderTask.GetCameraActor(); - bool pickingPossible = cameraActor->BuildPickingRay( screenCoordinates, viewport, results.rayOrigin, results.rayDirection ); + bool pickingPossible = cameraActor->BuildPickingRay( + screenCoordinates, + viewport, + results.rayOrigin, + results.rayDirection ); if( !pickingPossible ) { return false; diff --git a/dali/internal/event/render-tasks/render-task-impl.cpp b/dali/internal/event/render-tasks/render-task-impl.cpp index 90870aa..791ab34 100644 --- a/dali/internal/event/render-tasks/render-task-impl.cpp +++ b/dali/internal/event/render-tasks/render-task-impl.cpp @@ -357,10 +357,6 @@ bool RenderTask::TranslateCoordinates( Vector2& screenCoords ) const { screenCoords.x = localX; screenCoords.y = localY; - if( !localCamera->GetInvertYAxis() ) - { - screenCoords.y = actorSize.y - localY; - } } else { diff --git a/dali/internal/render/shaders/shader.cpp b/dali/internal/render/shaders/shader.cpp index 0275549..322bce5 100644 --- a/dali/internal/render/shaders/shader.cpp +++ b/dali/internal/render/shaders/shader.cpp @@ -430,33 +430,34 @@ Program& Shader::Apply( Context& context, case Dali::ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION : { /** - * Convert from viewport coordinates to GL view + * Convert coordinates from viewport to GL view space * - * Viewport - * (x,y) + * Viewport coordinate + * (0,0) * +-----+ * | | * | | * +-----+ - * (x+width,y+height) + * (width,height) * - * GL View Coordinates - * (-width/2,height/2) + * GL view space coordinates + * (width/2,-height/2) * +-----+ * | | * | | * +-----+ - * (width/2,-height/2) + * (-width/2,height/2) **/ const Rect< int >& viewport = context.GetViewport(); - value.x = value.x - viewport.width * 0.5f; - value.y = viewport.height * 0.5f - value.y; + value.x = viewport.width * 0.5f - value.x; + value.y = value.y - viewport.height * 0.5f; break; } case Dali::ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION : { - value.y *= -1.0f; + // Check diagram in COORDINATE_TYPE_VIEWPORT_POSITION + value.x *= -1.0f; break; } case Dali::ShaderEffect::COORDINATE_TYPE_TEXTURE_POSITION : diff --git a/dali/internal/update/manager/prepare-render-instructions.cpp b/dali/internal/update/manager/prepare-render-instructions.cpp index 0f4713f..71da5e9 100644 --- a/dali/internal/update/manager/prepare-render-instructions.cpp +++ b/dali/internal/update/manager/prepare-render-instructions.cpp @@ -245,14 +245,14 @@ inline void AddOpaqueRenderers( BufferIndex updateBufferIndex, } /** - * Function which sorts based on the calculated depth values + * Function which sorts based on the calculated depth values ordering them back to front * @param lhs item * @param rhs item - * @return true if right item is greater than left + * @return true if left item is greater than right */ bool SortByDepthSortValue( const RendererWithSortValue& lhs, const RendererWithSortValue& rhs ) { - return rhs.first < lhs.first; + return lhs.first > rhs.first; } /** @@ -287,7 +287,9 @@ inline void SortTransparentRenderItems( RenderList& transparentRenderList, Layer { RenderItem& item = transparentRenderList.GetItem( index ); // the default sorting function should get inlined here - sortingHelper[ index ].first = Internal::Layer::ZValue( item.GetModelViewMatrix().GetTranslation3(), layer.transparentRenderables[ index ]->GetSortModifier() ); + sortingHelper[ index ].first = Internal::Layer::ZValue( + item.GetModelViewMatrix().GetTranslation3(), + layer.transparentRenderables[ index ]->GetSortModifier() ); // keep the renderitem pointer in the helper so we can quickly reorder items after sort sortingHelper[ index ].second = &item; } @@ -298,13 +300,15 @@ inline void SortTransparentRenderItems( RenderList& transparentRenderList, Layer for( size_t index = 0; index < renderableCount; ++index ) { RenderItem& item = transparentRenderList.GetItem( index ); - sortingHelper[ index ].first = (*sortFunction)( item.GetModelViewMatrix().GetTranslation3(), layer.transparentRenderables[ index ]->GetSortModifier() ); + sortingHelper[ index ].first = (*sortFunction)( + item.GetModelViewMatrix().GetTranslation3(), + layer.transparentRenderables[ index ]->GetSortModifier() ); // keep the renderitem pointer in the helper so we can quickly reorder items after sort sortingHelper[ index ].second = &item; } } - // sort the values + // sort the renderers back to front, Z Axis point from near plane to far plane std::sort( sortingHelper.begin(), sortingHelper.end(), SortByDepthSortValue ); // reorder/repopulate the renderitems in renderlist to correct order based on sortinghelper diff --git a/dali/internal/update/node-attachments/scene-graph-camera-attachment.cpp b/dali/internal/update/node-attachments/scene-graph-camera-attachment.cpp index c3f4967..c26a2d3 100644 --- a/dali/internal/update/node-attachments/scene-graph-camera-attachment.cpp +++ b/dali/internal/update/node-attachments/scene-graph-camera-attachment.cpp @@ -46,16 +46,16 @@ namespace void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vector3& up) { - Vector3 vForward = target - eye; - vForward.Normalize(); + Vector3 vZ = target - eye; + vZ.Normalize(); - Vector3 vSide = vForward.Cross(up); - vSide.Normalize(); + Vector3 vX = up.Cross(vZ); + vX.Normalize(); - Vector3 vUp = vSide.Cross(vForward); - vUp.Normalize(); + Vector3 vY = vZ.Cross(vX); + vY.Normalize(); - result.SetInverseTransformComponents(vSide, vUp, -vForward, eye); + result.SetInverseTransformComponents(vX, vY, vZ, eye); } @@ -69,20 +69,21 @@ void Frustum(Matrix& result, float left, float right, float bottom, float top, f if ((near <= 0.0f) || (far <= 0.0f) || (deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f)) { + DALI_ASSERT_DEBUG("Invalid parameters passed into Frustum!"); return; } float* m = result.AsFloat(); - m[0] = 2.0f * near / deltaX; + m[0] = -2.0f * near / deltaX; m[1] = m[2] = m[3] = 0.0f; - m[5] = 2.0f * near / deltaY; + m[5] = -2.0f * near / deltaY; m[4] = m[6] = m[7] = 0.0f; m[8] = (right + left) / deltaX; m[9] = (top + bottom) / deltaY; - m[10] = -(near + far) / deltaZ; - m[11] = -1.0f; + m[10] = (near + far) / deltaZ; + m[11] = 1.0f; m[14] = -2.0f * near * far / deltaZ; m[12] = m[13] = m[15] = 0.0f; @@ -107,19 +108,19 @@ void Orthographic(Matrix& result, float left, float right, float bottom, float t !Equals(far, near) && "Cannot create orthographic projection with a zero edge" ); float *m = result.AsFloat(); - m[0] = 2.0f / deltaX; + m[0] = -2.0f / deltaX; m[1] = 0.0f; m[2] = 0.0f; m[3] = 0.0f; m[4] = 0.0f; - m[5] = 2.0f / deltaY; + m[5] = -2.0f / deltaY; m[6] = 0.0f; m[7] = 0.0f; m[8] = 0.0f; m[9] = 0.0f; - m[10] = -2.0f / deltaZ; + m[10] = 2.0f / deltaZ; m[11] = 0.0f; m[12] = -(right + left) / deltaX; m[13] = -(top + bottom) / deltaY; @@ -131,7 +132,7 @@ void Orthographic(Matrix& result, float left, float right, float bottom, float t const Dali::Camera::Type CameraAttachment::DEFAULT_TYPE( Dali::Camera::LOOK_AT_TARGET ); const Dali::Camera::ProjectionMode CameraAttachment::DEFAULT_MODE( Dali::Camera::PERSPECTIVE_PROJECTION ); -const bool CameraAttachment::DEFAULT_INVERT_Y_AXIS( true ); +const bool CameraAttachment::DEFAULT_INVERT_Y_AXIS( false ); const float CameraAttachment::DEFAULT_FIELD_OF_VIEW( 45.0f*(M_PI/180.0f) ); const float CameraAttachment::DEFAULT_ASPECT_RATIO( 4.0f/3.0f ); const float CameraAttachment::DEFAULT_LEFT_CLIPPING_PLANE(-240.0f); @@ -139,13 +140,12 @@ const float CameraAttachment::DEFAULT_RIGHT_CLIPPING_PLANE(240.0f); const float CameraAttachment::DEFAULT_TOP_CLIPPING_PLANE(-400.0f); const float CameraAttachment::DEFAULT_BOTTOM_CLIPPING_PLANE(400.0f); const float CameraAttachment::DEFAULT_NEAR_CLIPPING_PLANE( 800.0f ); // default height of the screen -const float CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE( DEFAULT_NEAR_CLIPPING_PLANE + 0xFFF ); // for a 16bit screen 4 bits per unit in depth buffer +const float CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE( DEFAULT_NEAR_CLIPPING_PLANE + 2.f * DEFAULT_NEAR_CLIPPING_PLANE ); const Vector3 CameraAttachment::DEFAULT_TARGET_POSITION( 0.0f, 0.0f, 0.0f ); CameraAttachment::CameraAttachment() : NodeAttachment(), - mLookAtMatrix(false), mUpdateViewFlag( UPDATE_COUNT ), mUpdateProjectionFlag( UPDATE_COUNT ), mType( DEFAULT_TYPE ), @@ -204,6 +204,7 @@ void CameraAttachment::SetProjectionMode( Dali::Camera::ProjectionMode mode ) void CameraAttachment::SetInvertYAxis( bool invertYAxis ) { mInvertYAxis = invertYAxis; + mUpdateProjectionFlag = UPDATE_COUNT; } void CameraAttachment::SetFieldOfView( float fieldOfView ) @@ -308,28 +309,11 @@ void CameraAttachment::Update( BufferIndex updateBufferIndex, const Node& owning // camera orientation taken from node - i.e. look in abitrary, unconstrained direction case Dali::Camera::FREE_LOOK: { - Matrix view(false); - Quaternion cameraRotation(owningNode.GetWorldRotation(updateBufferIndex)); - if( ! cameraRotation.IsIdentity()) - { - cameraRotation = cameraRotation*Quaternion(M_PI, Vector3::YAXIS); - } - view.SetInverseTransformComponents( Vector3::ONE, - cameraRotation, - owningNode.GetWorldPosition(updateBufferIndex) ); - Matrix& viewMatrix = mViewMatrix.Get(updateBufferIndex); - - if(mInvertYAxis) - { - viewMatrix.SetIdentityAndScale( Vector3(1.0f, -1.0f, 1.0f) ); - } - else - { - viewMatrix.SetIdentity(); - } - - Matrix::Multiply( viewMatrix, viewMatrix, view ); + viewMatrix.SetInverseTransformComponents( + Vector3::ONE, + owningNode.GetWorldRotation(updateBufferIndex), + owningNode.GetWorldPosition(updateBufferIndex) ); mViewMatrix.SetDirty(updateBufferIndex); break; @@ -338,25 +322,12 @@ void CameraAttachment::Update( BufferIndex updateBufferIndex, const Node& owning // camera orientation constrained to look at a target case Dali::Camera::LOOK_AT_TARGET: { - mLookAtMatrix = Matrix::IDENTITY; - - LookAt( mLookAtMatrix, + Matrix& viewMatrix = mViewMatrix.Get(updateBufferIndex); + LookAt( viewMatrix, owningNode.GetWorldPosition(updateBufferIndex), mTargetPosition, owningNode.GetWorldRotation(updateBufferIndex).Rotate(Vector3::YAXIS) ); - Matrix& viewMatrix = mViewMatrix.Get(updateBufferIndex); - - if(mInvertYAxis) - { - viewMatrix.SetIdentityAndScale( Vector3(1.0f, -1.0f, 1.0f) ); - } - else - { - viewMatrix.SetIdentity(); - } - Matrix::Multiply( viewMatrix, viewMatrix, mLookAtMatrix ); - mViewMatrix.SetDirty(updateBufferIndex); break; } @@ -387,7 +358,8 @@ void CameraAttachment::UpdateProjection( BufferIndex updateBufferIndex ) { case Dali::Camera::PERSPECTIVE_PROJECTION: { - Perspective( mProjectionMatrix.Get(updateBufferIndex), + Matrix &projectionMatrix = mProjectionMatrix.Get(updateBufferIndex); + Perspective( projectionMatrix, mFieldOfView, mAspectRatio, mNearClippingPlane, @@ -396,7 +368,8 @@ void CameraAttachment::UpdateProjection( BufferIndex updateBufferIndex ) } case Dali::Camera::ORTHOGRAPHIC_PROJECTION: { - Orthographic( mProjectionMatrix.Get(updateBufferIndex), + Matrix &projectionMatrix = mProjectionMatrix.Get(updateBufferIndex); + Orthographic( projectionMatrix, mLeftClippingPlane, mRightClippingPlane, mBottomClippingPlane, mTopClippingPlane, mNearClippingPlane, mFarClippingPlane ); diff --git a/dali/internal/update/node-attachments/scene-graph-camera-attachment.h b/dali/internal/update/node-attachments/scene-graph-camera-attachment.h index 93ff8ee..f256566 100644 --- a/dali/internal/update/node-attachments/scene-graph-camera-attachment.h +++ b/dali/internal/update/node-attachments/scene-graph-camera-attachment.h @@ -229,7 +229,6 @@ private: void UpdateInverseViewProjection( BufferIndex updateBufferIndex ); private: - Matrix mLookAtMatrix; ///< This is used during the view-matrix calculation. unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update diff --git a/dali/public-api/animation/constraints.cpp b/dali/public-api/animation/constraints.cpp index fe36232..a3131f4 100644 --- a/dali/public-api/animation/constraints.cpp +++ b/dali/public-api/animation/constraints.cpp @@ -271,23 +271,20 @@ Vector3 SourceHeightFixedWidth::operator()( const Vector3& current, const Proper // LookAt /////////////////////////////////////////////////////////////////////////////////////////////////// -static Quaternion LookAtTarget( const Vector3& vForward, const Quaternion& targetRotation ) +static Quaternion LookAtTarget( const Vector3& vZ, const Quaternion& targetRotation ) { - Vector3 vRight; - Vector3 vUp; - - Vector3 targetUp(targetRotation.Rotate(-Vector3::YAXIS)); - targetUp.Normalize(); + Vector3 targetY(targetRotation.Rotate(Vector3::YAXIS)); + targetY.Normalize(); // Camera Right vector is perpendicular to forward & target up - vRight = vForward.Cross(targetUp); - vRight.Normalize(); + Vector3 vX = targetY.Cross(vZ); + vX.Normalize(); // Camera Up vector is perpendicular to forward and right - vUp = vForward.Cross(vRight); - vUp.Normalize(); + Vector3 vY = vZ.Cross(vX); + vY.Normalize(); - return Quaternion( vRight, vUp, vForward ); + return Quaternion( vX, vY, vZ ); } Dali::Quaternion LookAt( const Dali::Quaternion& current,