[dali_2.1.1] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / camera-parameters.cpp
index 875c58b..d895255 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -16,9 +16,9 @@
  */
 #include "dali-scene-loader/public-api/camera-parameters.h"
 #include "dali-scene-loader/public-api/utils.h"
+#include "dali/integration-api/debug.h"
 #include "dali/public-api/actors/camera-actor.h"
 #include "dali/public-api/math/quaternion.h"
-#include "dali/integration-api/debug.h"
 
 namespace Dali
 {
@@ -38,10 +38,10 @@ namespace
  * @param[in] far The distance to the far depth clipping plane.
  * @param[in] invertYAxis Whether to invert the 'Y' axis.
  */
-void Frustum( Matrix& result, float left, float right, float bottom, float top, float nearPlane, float farPlane, bool invertYAxis )
+void Frustum(Matrix& result, float left, float right, float bottom, float top, float nearPlane, float farPlane, bool invertYAxis)
 {
   float deltaZ = farPlane - nearPlane;
-  if ((nearPlane <= 0.0f) || (farPlane <= 0.0f) || Equals(right, left) || Equals(bottom, top) || (deltaZ <= 0.0f))
+  if((nearPlane <= 0.0f) || (farPlane <= 0.0f) || Equals(right, left) || Equals(bottom, top) || (deltaZ <= 0.0f))
   {
     DALI_LOG_ERROR("Invalid parameters passed into Frustum!\n");
     DALI_ASSERT_DEBUG("Invalid parameters passed into Frustum!");
@@ -54,14 +54,14 @@ void Frustum( Matrix& result, float left, float right, float bottom, float top,
   result.SetIdentity();
 
   float* m = result.AsFloat();
-  m[0] = -2.0f * nearPlane / deltaX;
+  m[0]     = -2.0f * nearPlane / deltaX;
   m[1] = m[2] = m[3] = 0.0f;
 
   m[5] = -2.0f * nearPlane / deltaY;
   m[4] = m[6] = m[7] = 0.0f;
 
-  m[8] = (right + left) / deltaX;
-  m[9] = (top + bottom) / deltaY;
+  m[8]  = (right + left) / deltaX;
+  m[9]  = (top + bottom) / deltaY;
   m[10] = (nearPlane + farPlane) / deltaZ;
   m[11] = 1.0f;
 
@@ -81,12 +81,12 @@ void Frustum( Matrix& result, float left, float right, float bottom, float top,
  * @param[in] farPlane The distance to the far depth clipping plane.
  * @param[in] invertYAxis Whether to invert the 'Y' axis.
  */
-void Perspective( Matrix& result, float fovy, float aspect, float nearPlane, float farPlane, bool invertYAxis )
+void Perspective(Matrix& result, float fovy, float aspect, float nearPlane, float farPlane, bool invertYAxis)
 {
-  float frustumH = tanf( fovy * 0.5f ) * nearPlane;
+  float frustumH = tanf(fovy * 0.5f) * nearPlane;
   float frustumW = frustumH * aspect;
 
-  Frustum( result, -frustumW, frustumW, -frustumH, frustumH, nearPlane, farPlane, invertYAxis );
+  Frustum(result, -frustumW, frustumW, -frustumH, frustumH, nearPlane, farPlane, invertYAxis);
 }
 
 /**
@@ -103,7 +103,7 @@ void Perspective( Matrix& result, float fovy, float aspect, float nearPlane, flo
 */
 void Orthographic(Matrix& result, float left, float right, float bottom, float top, float nearPlane, float farPlane, bool invertYAxis)
 {
-  if (Equals(right, left) || Equals(top, bottom) || Equals(farPlane, nearPlane))
+  if(Equals(right, left) || Equals(top, bottom) || Equals(farPlane, nearPlane))
   {
     DALI_LOG_ERROR("Cannot create orthographic projection matrix with a zero dimension.\n");
     DALI_ASSERT_DEBUG("Cannot create orthographic projection matrix with a zero dimension.");
@@ -114,19 +114,19 @@ void Orthographic(Matrix& result, float left, float right, float bottom, float t
   float deltaY = invertYAxis ? bottom - top : top - bottom;
   float deltaZ = farPlane - nearPlane;
 
-  float *m = result.AsFloat();
-  m[0] = -2.0f / deltaX;
-  m[1] = 0.0f;
-  m[2] = 0.0f;
-  m[3] = 0.0f;
+  floatm = result.AsFloat();
+  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[6] = 0.0f;
   m[7] = 0.0f;
 
-  m[8] = 0.0f;
-  m[9] = 0.0f;
+  m[8]  = 0.0f;
+  m[9]  = 0.0f;
   m[10] = 2.0f / deltaZ;
   m[11] = 0.0f;
   m[12] = -(right + left) / deltaX;
@@ -135,51 +135,50 @@ void Orthographic(Matrix& result, float left, float right, float bottom, float t
   m[15] = 1.0f;
 }
 
-} // nonamespace
+} // namespace
 
 ViewProjection CameraParameters::GetViewProjection() const
 {
   ViewProjection viewProjection;
   // The projection matrix.
-  if (isPerspective)
+  if(isPerspective)
   {
     Perspective(viewProjection.GetProjection(),
-      Radian(Degree(yFov)),
-      1.f,
-      zNear,
-      zFar,
-      true);
+                Radian(Degree(yFov)),
+                1.f,
+                zNear,
+                zFar,
+                true);
   }
   else
   {
     Orthographic(viewProjection.GetProjection(),
-      orthographicSize.x,
-      orthographicSize.y,
-      orthographicSize.z,
-      orthographicSize.w,
-      zNear,
-      zFar,
-      true);
-
+                 orthographicSize.x,
+                 orthographicSize.y,
+                 orthographicSize.z,
+                 orthographicSize.w,
+                 zNear,
+                 zFar,
+                 true);
   }
 
   // The view matrix.
   const Quaternion viewQuaternion(ANGLE_180, Vector3::YAXIS);
-  Vector3 translation;
-  Quaternion cameraOrientation;
-  Vector3 scale;
+  Vector3          translation;
+  Quaternion       cameraOrientation;
+  Vector3          scale;
   matrix.GetTransformComponents(translation, cameraOrientation, scale);
   cameraOrientation *= viewQuaternion;
 
   viewProjection.GetView().SetInverseTransformComponents(scale,
-    cameraOrientation,
-    translation);
+                                                         cameraOrientation,
+                                                         translation);
 
   viewProjection.Update();
   return viewProjection;
 }
 
-void CameraParameters::CalculateTransformComponents(Vector3 & position, Quaternion & orientation, Vector3 & scale) const
+void CameraParameters::CalculateTransformComponents(Vector3& position, Quaternion& orientation, Vector3& scale) const
 {
   matrix.GetTransformComponents(position, orientation, scale);
 
@@ -193,7 +192,7 @@ void CameraParameters::ConfigureCamera(CameraActor& camera) const
 {
   SetActorCentered(camera);
 
-  if (isPerspective)
+  if(isPerspective)
   {
     camera.SetProjectionMode(Camera::PERSPECTIVE_PROJECTION);
     camera.SetNearClippingPlane(zNear);
@@ -204,16 +203,16 @@ void CameraParameters::ConfigureCamera(CameraActor& camera) const
   {
     camera.SetProjectionMode(Camera::ORTHOGRAPHIC_PROJECTION);
     camera.SetOrthographicProjection(orthographicSize.x,
-      orthographicSize.y,
-      orthographicSize.z,
-      orthographicSize.w,
-      zNear,
-      zFar);
+                                     orthographicSize.y,
+                                     orthographicSize.z,
+                                     orthographicSize.w,
+                                     zNear,
+                                     zFar);
   }
 
   // model
-  Vector3 camTranslation;
-  Vector3 camScale;
+  Vector3    camTranslation;
+  Vector3    camScale;
   Quaternion camOrientation;
   CalculateTransformComponents(camTranslation, camOrientation, camScale);
 
@@ -223,5 +222,5 @@ void CameraParameters::ConfigureCamera(CameraActor& camera) const
   camera.SetProperty(Actor::Property::SCALE, camScale);
 }
 
-}
-}
+} // namespace SceneLoader
+} // namespace Dali