Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / rendering-skybox / look-camera.cpp
index 00f38fc..39636db 100644 (file)
@@ -17,9 +17,9 @@
 
 #include "look-camera.h"
 
+#include <dali/public-api/events/touch-event.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
 #include <dali/public-api/render-tasks/render-task.h>
-#include <dali/public-api/events/touch-event.h>
 
 using namespace Dali;
 
@@ -27,52 +27,52 @@ namespace
 {
 // Input sensitivity, the larger value, the more sensitive input
 // Default value has been chosen empirically
-const float   CAMERA_SENSITIVITY        ( 90.0f );
+const float CAMERA_SENSITIVITY(90.0f);
 
 // Vertical angle limit of the camera
-const float   CAMERA_VERTICAL_LIMIT     ( 80.0f );
+const float CAMERA_VERTICAL_LIMIT(80.0f);
 
 // Position where camera is instantiated by default
-const Vector3 CAMERA_DEFAULT_POSITION   ( 0.0f, 0.0f, 3.0f );
+const Vector3 CAMERA_DEFAULT_POSITION(0.0f, 0.0f, 3.0f);
 
 // Field-of-View in degrees
-const float   CAMERA_DEFAULT_FOV        ( 60.0f );
+const float CAMERA_DEFAULT_FOV(60.0f);
 
 // Near plane
-const float   CAMERA_DEFAULT_NEAR       ( 0.1f );
+const float CAMERA_DEFAULT_NEAR(0.1f);
 
 // Far plane
-const float   CAMERA_DEFAULT_FAR        ( 100.0f );
+const float CAMERA_DEFAULT_FAR(100.0f);
 
 // Default forward vector
-const Vector3 CAMERA_FORWARD            ( 0.0f, 0.0f, 1.0f );
+const Vector3 CAMERA_FORWARD(0.0f, 0.0f, 1.0f);
 
 // Default up vector
-const Vector3 CAMERA_UP                 ( Vector3::YAXIS );
-}
+const Vector3 CAMERA_UP(Vector3::YAXIS);
+} // namespace
 
 LookCamera::LookCamera()
-: mCameraYawPitch( 0.0f, 180.0f ),
-  mFovY( CAMERA_DEFAULT_FOV ),
-  mNear( CAMERA_DEFAULT_NEAR ),
-  mFar( CAMERA_DEFAULT_FAR ),
-  mCameraPosition( CAMERA_DEFAULT_POSITION )
+: mCameraYawPitch(0.0f, 180.0f),
+  mFovY(CAMERA_DEFAULT_FOV),
+  mNear(CAMERA_DEFAULT_NEAR),
+  mFar(CAMERA_DEFAULT_FAR),
+  mCameraPosition(CAMERA_DEFAULT_POSITION)
 {
 }
 
 LookCamera::~LookCamera()
 {
   mTimer.Stop();
-  mCameraActor.Remove( mInterceptorActor );
+  mCameraActor.Remove(mInterceptorActor);
 }
 
-void LookCamera::Initialise( Window window, const Vector3& position, float fovY, float near, float far )
+void LookCamera::Initialise(Window window, const Vector3& position, float fovY, float near, float far)
 {
   mWindow = window;
 
   mFovY = fovY;
   mNear = near;
-  mFar = far;
+  mFar  = far;
 
   // Camera position is shadowed in order to avoid using.GetCurrentProperty< Vector3 >( Actor::Property::POSITION )
   mCameraPosition = position;
@@ -84,8 +84,8 @@ void LookCamera::Initialise( Window window, const Vector3& position, float fovY,
   CreateInterceptorActor();
 
   // Start timer
-  mTimer = Timer::New( 16 );
-  mTimer.TickSignal().Connect( this, &LookCamera::OnTick );
+  mTimer = Timer::New(16);
+  mTimer.TickSignal().Connect(this, &LookCamera::OnTick);
   mTimer.Start();
 }
 
@@ -95,24 +95,24 @@ bool LookCamera::OnTick()
 
   // ---------------------------------------------------------------------
   // update rotation
-  Vector2 tmp( mScreenLookDelta );
+  Vector2 tmp(mScreenLookDelta);
   mScreenLookDelta = Vector2::ZERO;
 
-  float yaw = ( (tmp.y / windowSize.x ) * CAMERA_SENSITIVITY );
-  float pitch = ( (tmp.x / windowSize.y ) * CAMERA_SENSITIVITY );
+  float yaw   = ((tmp.y / windowSize.x) * CAMERA_SENSITIVITY);
+  float pitch = ((tmp.x / windowSize.y) * CAMERA_SENSITIVITY);
   mCameraYawPitch.x -= yaw;
   mCameraYawPitch.y -= pitch;
-  if( abs( mCameraYawPitch.x ) > CAMERA_VERTICAL_LIMIT )
+  if(abs(mCameraYawPitch.x) > CAMERA_VERTICAL_LIMIT)
   {
-    mCameraYawPitch.x = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.x < 0) ? -1.0f : 1.0f );
+    mCameraYawPitch.x = CAMERA_VERTICAL_LIMIT * ((mCameraYawPitch.x < 0) ? -1.0f : 1.0f);
   }
 
   Quaternion rotation;
-  Quaternion rotX( Degree( mCameraYawPitch.x), Vector3( 1.0f, 0.0f, 0.0f ) );
-  Quaternion rotY( Degree( mCameraYawPitch.y), Vector3( 0.0f, 1.0f, 0.0f ) );
-  rotation = ( rotY * rotX );
+  Quaternion rotX(Degree(mCameraYawPitch.x), Vector3(1.0f, 0.0f, 0.0f));
+  Quaternion rotY(Degree(mCameraYawPitch.y), Vector3(0.0f, 1.0f, 0.0f));
+  rotation = (rotY * rotX);
 
-  mCameraActor.SetProperty( Actor::Property::ORIENTATION, rotation );
+  mCameraActor.SetProperty(Actor::Property::ORIENTATION, rotation);
 
   return true;
 }
@@ -120,15 +120,15 @@ bool LookCamera::OnTick()
 void LookCamera::InitialiseDefaultCamera()
 {
   mCameraActor = mWindow.GetRenderTaskList().GetTask(0).GetCameraActor();
-  mCameraActor.SetProperty( Dali::Actor::Property::NAME, "LookCamera" );
-  mCameraActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-  mCameraActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  mCameraActor.SetFieldOfView( Radian( Degree( mFovY ) ) );
+  mCameraActor.SetProperty(Dali::Actor::Property::NAME, "LookCamera");
+  mCameraActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+  mCameraActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+  mCameraActor.SetFieldOfView(Radian(Degree(mFovY)));
 
   // should be read from file
-  mCameraActor.SetNearClippingPlane( mNear );
-  mCameraActor.SetFarClippingPlane( mFar );
-  mCameraActor.SetProperty( Actor::Property::POSITION, mCameraPosition );
+  mCameraActor.SetNearClippingPlane(mNear);
+  mCameraActor.SetFarClippingPlane(mFar);
+  mCameraActor.SetProperty(Actor::Property::POSITION, mCameraPosition);
 }
 
 void LookCamera::CreateInterceptorActor()
@@ -136,40 +136,39 @@ void LookCamera::CreateInterceptorActor()
   Vector2 windowSize = mWindow.GetSize();
 
   mInterceptorActor = Actor::New();
-  mInterceptorActor.SetProperty( Dali::Actor::Property::NAME, "InputInterceptor" );
-  mInterceptorActor.SetProperty( Actor::Property::SIZE, Vector3( windowSize.width, windowSize.height, 1 ) );
-  mInterceptorActor.SetProperty( Actor::Property::POSITION, Vector3( 0.0, 0.0, 1.0  ) );
-  mInterceptorActor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-  mInterceptorActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  mCameraActor.Add( mInterceptorActor );
+  mInterceptorActor.SetProperty(Dali::Actor::Property::NAME, "InputInterceptor");
+  mInterceptorActor.SetProperty(Actor::Property::SIZE, Vector3(windowSize.width, windowSize.height, 1));
+  mInterceptorActor.SetProperty(Actor::Property::POSITION, Vector3(0.0, 0.0, 1.0));
+  mInterceptorActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+  mInterceptorActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+  mCameraActor.Add(mInterceptorActor);
 
   // Connect TouchedSignal to interceptor actor
-  mInterceptorActor.TouchedSignal().Connect( this, &LookCamera::OnTouch );
+  mInterceptorActor.TouchedSignal().Connect(this, &LookCamera::OnTouch);
 }
 
-bool LookCamera::OnTouch( Actor actor, const TouchEvent& touch )
+bool LookCamera::OnTouch(Actor actor, const TouchEvent& touch)
 {
-  for( int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i )
+  for(int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i)
   {
-    Vector2 position( touch.GetScreenPosition( i ) );
+    Vector2 position(touch.GetScreenPosition(i));
 
     // touch started
-    if( touch.GetState( i ) == PointState::STARTED )
+    if(touch.GetState(i) == PointState::STARTED)
     {
       mOldTouchLookPosition = position;
     }
-    else if( touch.GetState( i ) == PointState::FINISHED ||
-             touch.GetState( i ) == PointState::LEAVE ||
-             touch.GetState( i ) == PointState::INTERRUPTED
-             )
+    else if(touch.GetState(i) == PointState::FINISHED ||
+            touch.GetState(i) == PointState::LEAVE ||
+            touch.GetState(i) == PointState::INTERRUPTED)
     {
-      mScreenLookDelta = Vector2::ZERO;
+      mScreenLookDelta      = Vector2::ZERO;
       mOldTouchLookPosition = Vector2::ZERO;
     }
     else // on motion
     {
-      mScreenLookDelta.x += ( position.x - mOldTouchLookPosition.x );
-      mScreenLookDelta.y += ( position.y - mOldTouchLookPosition.y );
+      mScreenLookDelta.x += (position.x - mOldTouchLookPosition.x);
+      mScreenLookDelta.y += (position.y - mOldTouchLookPosition.y);
       mOldTouchLookPosition = position;
     }
   }