Changes after TouchedSignal changes
[platform/core/uifw/dali-demo.git] / examples / fpp-game / game-camera.cpp
index 7215c5a..0b7255b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
 
 #include "game-camera.h"
 
-#include <dali/public-api/common/stage.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-data.h>
 #include <dali/public-api/events/touch-event.h>
 
 using namespace Dali;
@@ -69,14 +67,16 @@ GameCamera::~GameCamera()
   mCameraActor.Remove( mInterceptorActor );
 }
 
-void GameCamera::Initialise( float fovY, float near, float far )
+void GameCamera::Initialise( CameraActor defaultCamera, float fovY, float near, float far, const Vector2& sceneSize )
 {
+  mCameraActor = defaultCamera;
+
   mFovY = fovY;
   mNear = near;
   mFar = far;
 
-  Vector2 stageSize = Stage::GetCurrent().GetSize();
-  mPortraitMode = stageSize.x < stageSize.y ? true : false;
+  mSceneSize = sceneSize;
+  mPortraitMode = mSceneSize.x < mSceneSize.y ? true : false;
 
   // Initialise default camera
   InitialiseDefaultCamera();
@@ -92,8 +92,6 @@ void GameCamera::Initialise( float fovY, float near, float far )
 
 bool GameCamera::OnTick()
 {
-  Vector2 stageSize = Stage::GetCurrent().GetSize();
-
   // ---------------------------------------------------------------------
   // update rotation
   Vector2 tmp( mScreenLookDelta );
@@ -101,8 +99,8 @@ bool GameCamera::OnTick()
 
   if( mPortraitMode )
   {
-    float yaw = ( (tmp.y / stageSize.y ) * CAMERA_SENSITIVITY );
-    float pitch = ( (tmp.x / stageSize.x ) * CAMERA_SENSITIVITY );
+    float yaw = ( (tmp.y / mSceneSize.y ) * CAMERA_SENSITIVITY );
+    float pitch = ( (tmp.x / mSceneSize.x ) * CAMERA_SENSITIVITY );
     mCameraYawPitch.y -= yaw;
     mCameraYawPitch.x -= pitch;
     if( abs( mCameraYawPitch.y ) > CAMERA_VERTICAL_LIMIT )
@@ -112,8 +110,8 @@ bool GameCamera::OnTick()
   }
   else
   {
-    float yaw = ( (tmp.y / stageSize.x ) * CAMERA_SENSITIVITY );
-    float pitch = ( (tmp.x / stageSize.y ) * CAMERA_SENSITIVITY );
+    float yaw = ( (tmp.y / mSceneSize.x ) * CAMERA_SENSITIVITY );
+    float pitch = ( (tmp.x / mSceneSize.y ) * CAMERA_SENSITIVITY );
     mCameraYawPitch.x -= yaw;
     mCameraYawPitch.y -= pitch;
     if( abs( mCameraYawPitch.x ) > CAMERA_VERTICAL_LIMIT )
@@ -134,7 +132,7 @@ bool GameCamera::OnTick()
   {
     rotation = ( rotY * rotX );
   }
-  mCameraActor.SetOrientation( rotation );
+  mCameraActor.SetProperty( Actor::Property::ORIENTATION, rotation );
 
   // ---------------------------------------------------------------------
   // update position
@@ -154,8 +152,8 @@ bool GameCamera::OnTick()
 
   sidewaysVector.Normalize();
 
-  const float forwardSpeed( mScreenWalkDelta.y / stageSize.y );
-  const float sidewaysSpeed( mScreenWalkDelta.x / stageSize.x );
+  const float forwardSpeed( mScreenWalkDelta.y / mSceneSize.y );
+  const float sidewaysSpeed( mScreenWalkDelta.x / mSceneSize.x );
 
   // Adjust walking speed
   if ( mPortraitMode )
@@ -169,7 +167,7 @@ bool GameCamera::OnTick()
 
   position += sidewaysVector * (sidewaysSpeed * 0.5f);
 
-  mCameraActor.SetPosition( position );
+  mCameraActor.SetProperty( Actor::Property::POSITION, position );
 
   mCameraPosition = position;
 
@@ -178,42 +176,36 @@ bool GameCamera::OnTick()
 
 void GameCamera::InitialiseDefaultCamera()
 {
-  Stage stage = Stage::GetCurrent();
-  mCameraActor = stage.GetRenderTaskList().GetTask(0).GetCameraActor();
-  mCameraActor.SetName( "GameCamera" );
-  mCameraActor.SetAnchorPoint( AnchorPoint::CENTER );
-  mCameraActor.SetParentOrigin( ParentOrigin::CENTER );
+  mCameraActor.SetProperty( Dali::Actor::Property::NAME, "GameCamera" );
+  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.SetPosition( CAMERA_DEFAULT_POSITION );
+  mCameraActor.SetProperty( Actor::Property::POSITION, CAMERA_DEFAULT_POSITION );
 
-  // Camera position is shadowed in order to avoid using GetCurrentPosition()
+  // Camera position is shadowed in order to avoid using.GetCurrentProperty< Vector3 >( Actor::Property::POSITION )
   mCameraPosition = CAMERA_DEFAULT_POSITION;
 }
 
 void GameCamera::CreateInterceptorActor()
 {
-  Stage stage = Stage::GetCurrent();
-
   mInterceptorActor = Actor::New();
-  mInterceptorActor.SetName( "GameInputInterceptor" );
-  mInterceptorActor.SetSize( Vector3( stage.GetSize().x, stage.GetSize().y, 1 ) );
-  mInterceptorActor.SetPosition( Vector3( 0.0, 0.0, 1.0  ) );
-  mInterceptorActor.SetAnchorPoint( AnchorPoint::CENTER );
-  mInterceptorActor.SetParentOrigin( ParentOrigin::CENTER );
+  mInterceptorActor.SetProperty( Dali::Actor::Property::NAME, "GameInputInterceptor" );
+  mInterceptorActor.SetProperty( Actor::Property::SIZE, Vector3( mSceneSize.x, mSceneSize.y, 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 TouchSignal to interceptor actor
-  mInterceptorActor.TouchSignal().Connect( this, &GameCamera::OnTouch );
+  // Connect TouchedSignal to interceptor actor
+  mInterceptorActor.TouchedSignal().Connect( this, &GameCamera::OnTouch );
 }
 
-bool GameCamera::OnTouch( Actor actor, const TouchData& touch )
+bool GameCamera::OnTouch( Actor actor, const TouchEvent& touch )
 {
-  Stage stage = Stage::GetCurrent();
-
   for( int i = 0; i < (int)touch.GetPointCount() && i < 3; ++i )
   {
     int id = touch.GetDeviceId( i );
@@ -224,13 +216,13 @@ bool GameCamera::OnTouch( Actor actor, const TouchData& touch )
     {
       position.x = tmp.y;
       position.y = tmp.x;
-      halfWindowSize = stage.GetSize().y / 2;
+      halfWindowSize = mSceneSize.y / 2;
     }
     else
     {
       position.x = tmp.x;
       position.y = tmp.y;
-      halfWindowSize = stage.GetSize().x / 2;
+      halfWindowSize = mSceneSize.x / 2;
     }
 
     // touch started