Reimplement InvertYAxis API in CameraActor. 13/18213/6
authorFrancisco Santos <f1.santos@samsung.com>
Tue, 18 Mar 2014 11:41:57 +0000 (11:41 +0000)
committerFrancisco Santos <f1.santos@samsung.com>
Tue, 18 Mar 2014 17:10:47 +0000 (17:10 +0000)
The InvertYAxis now has a slightly different meaning.
The Y invertion is done in the projection matrix.

Change-Id: I5af0b8fb0856b69787889c35ebfa7fceb07541cb
Signed-off-by: Francisco Santos <f1.santos@samsung.com>
capi/dali/public-api/actors/camera-actor.h
dali/internal/update/node-attachments/scene-graph-camera-attachment.cpp

index 1bd40a0..dadb7c8 100644 (file)
@@ -244,10 +244,9 @@ public:
   Vector3 GetTargetPosition() const;
 
   /**
-   * @brief Set whether the Y axis is inverted in the update calculation.
+   * @brief Request for an inversion on the Y axis on the projection calculation.
    *
-   * Inverting the Y axis allows +ve Y down in main coordinate system
-   * The default value is inverted.
+   * The default value is not inverted.
    * @param[in] invertYAxis True if the Y axis should be inverted
    */
   void SetInvertYAxis(bool invertYAxis);
index c26a2d3..11b1ce9 100644 (file)
@@ -59,20 +59,21 @@ void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vec
 }
 
 
-void Frustum(Matrix& result, float left, float right, float bottom, float top, float near, float far)
+void Frustum(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis)
 {
-  float deltaX = right - left;
-  float deltaY = top - bottom;
   float deltaZ = far - near;
-
-  result.SetIdentity();
-
-  if ((near <= 0.0f) || (far <= 0.0f) || (deltaX <= 0.0f) || (deltaY <= 0.0f) || (deltaZ <= 0.0f))
+  if ((near <= 0.0f) || (far <= 0.0f) || Equals(right, left) || Equals(bottom, top) || (deltaZ <= 0.0f))
   {
+    DALI_LOG_ERROR("Invalid parameters passed into Frustum!");
     DALI_ASSERT_DEBUG("Invalid parameters passed into Frustum!");
     return;
   }
 
+  float deltaX = right - left;
+  float deltaY = invertYAxis ? bottom - top : top - bottom;
+
+  result.SetIdentity();
+
   float* m = result.AsFloat();
   m[0] = -2.0f * near / deltaX;
   m[1] = m[2] = m[3] = 0.0f;
@@ -89,24 +90,27 @@ 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)
+void Perspective(Matrix& result, float fovy, float aspect, float near, float far, bool invertYAxis)
 {
   float frustumH = tanf( fovy / 2 ) * near;
   float frustumW = frustumH * aspect;
 
-  Frustum(result, -frustumW, frustumW, -frustumH, frustumH, near, far);
+  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)
+void Orthographic(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis)
 {
+  if ( Equals(right, left) || Equals(top, bottom) || Equals(far, near) )
+  {
+    DALI_LOG_ERROR( "Cannot create orthographic projection matrix with a zero dimension." );
+    DALI_ASSERT_DEBUG( "Cannot create orthographic projection matrix with a zero dimension." );
+    return;
+  }
+
   float deltaX = right - left;
-  float deltaY = top - bottom;
+  float deltaY = invertYAxis ? bottom - top : top - bottom;
   float deltaZ = far - near;
 
-  DALI_ASSERT_ALWAYS( !Equals(right, left) &&
-                      !Equals(top, bottom) &&
-                      !Equals(far, near) && "Cannot create orthographic projection with a zero edge" );
-
   float *m = result.AsFloat();
   m[0] = -2.0f / deltaX;
   m[1] = 0.0f;
@@ -363,7 +367,8 @@ void CameraAttachment::UpdateProjection( BufferIndex updateBufferIndex )
                        mFieldOfView,
                        mAspectRatio,
                        mNearClippingPlane,
-                       mFarClippingPlane );
+                       mFarClippingPlane,
+                       mInvertYAxis );
           break;
         }
         case Dali::Camera::ORTHOGRAPHIC_PROJECTION:
@@ -372,7 +377,8 @@ void CameraAttachment::UpdateProjection( BufferIndex updateBufferIndex )
           Orthographic( projectionMatrix,
                         mLeftClippingPlane,   mRightClippingPlane,
                         mBottomClippingPlane, mTopClippingPlane,
-                        mNearClippingPlane,   mFarClippingPlane );
+                        mNearClippingPlane,   mFarClippingPlane,
+                        mInvertYAxis );
           break;
         }
       }