Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / fpp-game / game-camera.h
1 #ifndef GAME_CAMERA_H
2 #define GAME_CAMERA_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include <dali/public-api/actors/camera-actor.h>
22 #include <dali/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/math/vector2.h>
24
25 /**
26  * @brief The GameCamera class
27  * First-person camera implementation with handling user input
28  *
29  * GameCamera uses the DALi camera for displaying 3D game view.
30  * Additionally it handles simple user input by attaching fullscreen
31  * sized 'interceptor' Actor to the front of the CameraActor ( to be always
32  * parallel to the view ). It is necessary, as with changing camera orientation
33  * the the window cannot be used as a touch signal receiver ( it will simply
34  * go offscreen with camera rotation ).
35  *
36  * DALi camera uses left-handed coordinate system.
37  *
38  * The control scheme assumes that left half of the screen is responsible for
39  * movement, the right half of screen is a rotation.
40  */
41 class GameCamera : public Dali::ConnectionTracker
42 {
43 public:
44   /**
45    * Creates an instance of GameCamera
46    */
47   GameCamera();
48
49   /**
50    * Destroys an instance of GameCamera
51    */
52   ~GameCamera();
53
54   /**
55    * Initialise with given fovY, near, far
56    * @param[in] defaultCamera The default camera used by the scene
57    * @param[in] fovY Field of view in degrees
58    * @param[in] near Near plane
59    * @param[in] far Far Plane
60    * @param[in] sceneSize The size of the scene this is looking at
61    */
62   void Initialise(Dali::CameraActor defaultCamera, float fov, float near, float far, const Dali::Vector2& sceneSize);
63
64 private:
65   /**
66    * Sets up a perspective camera using Dali default camera
67    */
68   void InitialiseDefaultCamera();
69
70   /**
71    * Creates 'interceptor' actor. Interceptor actor is always parallel
72    * to the camera and positioned little bit in front of it in order to
73    * intercept user input.
74    */
75   void CreateInterceptorActor();
76
77   /**
78    * Handles onTouch signal on the 'interceptor' actor
79    * @param[in] actor Actor receiving signal
80    * @param[in] touch Touch data
81    */
82   bool OnTouch(Dali::Actor actor, const Dali::TouchEvent& touch);
83
84   /**
85    * Handles camera tick() update
86    * @return true if continue running timer, false otherwise
87    */
88   bool OnTick();
89
90 private:
91   Dali::CameraActor mCameraActor;      /// Camera actor
92   Dali::Actor       mInterceptorActor; /// Actor intercepting user input
93
94   Dali::Timer mTimer; /// Per-frame timer
95
96   Dali::Vector2 mScreenLookDelta;      /// Look delta vector in screen space
97   Dali::Vector2 mScreenWalkDelta;      /// Walk delta vector in screen space
98   Dali::Vector2 mOldTouchLookPosition; /// Previous look vector in screen space
99   Dali::Vector2 mOldTouchWalkPosition; /// Previuus walk vector in screen space
100
101   Dali::Vector2 mCameraYawPitch; /// Camera yaw-pitch angles
102
103   float mFovY; /// Camera field-of-view
104   float mNear; /// Near plane
105   float mFar;  /// Far plane
106
107   int mWalkingTouchId; /// Touch device id bound to the walking action
108   int mLookingTouchId; /// Touch device id bound to the looking action
109
110   Dali::Vector3 mCameraPosition; /// Current camera position ( shadowing the actor position )
111   Dali::Vector2 mSceneSize;      /// The size of the scene we are looking at
112
113   bool mPortraitMode; /// flag if window is in portrait mode ( physically window width < height )
114 };
115
116 #endif