[Tizen] LookAt API for actor
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-coords.h
1 #ifndef DALI_INTERNAL_EVENT_ACTORS_ACTOR_COORDS_H
2 #define DALI_INTERNAL_EVENT_ACTORS_ACTOR_COORDS_H
3
4 /*
5  * Copyright (c) 2023 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 #include <dali/internal/event/actors/camera-actor-impl.h>
21 #include <dali/internal/event/render-tasks/render-task-impl.h>
22 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
23 #include <dali/public-api/math/matrix.h>
24 #include <dali/public-api/math/vector3.h>
25 #include <dali/public-api/math/viewport.h>
26
27 namespace Dali::Internal
28 {
29 /**
30  * Convert screen coordinates to local coordinates
31  *
32  * @param[in] viewMatrix The view matrix used to display this entity
33  * @param[in] projectionMatrix The projection matrix used to display this entity
34  * @param[in] worldMatrix The world matrix of this entity
35  * @param[in] currentSize The 2d bounding box for this entity
36  * @param[in] viewport The viewport used for drawing
37  * @param[out] localX The local X coordinate
38  * @param[out] localY The local Y coordinate
39  * @param[in] screenX The screen X coordinate
40  * @param[in] screenY The screen Y coordinate
41  * @return true if the conversion was successful
42  */
43 bool ConvertScreenToLocal(const Matrix&   viewMatrix,
44                           const Matrix&   projectionMatrix,
45                           const Matrix&   worldMatrix,
46                           const Vector3&  currentSize,
47                           const Viewport& viewport,
48                           float&          localX,
49                           float&          localY,
50                           float           screenX,
51                           float           screenY);
52
53 /**
54  * Convert screen coordinates to local coordinates
55  *
56  * @param[in] renderTask The render task used to display this entity
57  * @param[in] worldMatrix The world matrix of this entity
58  * @param[in] currentSize The 2d bounding box for this entity
59  * @param[out] localX The local X coordinate
60  * @param[out] localY The local Y coordinate
61  * @param[in] screenX The screen X coordinate
62  * @param[in] screenY The screen Y coordinate
63  * @return true if the conversion was successful
64  */
65 bool ConvertScreenToLocalRenderTask(
66   const RenderTask& renderTask,
67   const Matrix&     worldMatrix,
68   const Vector3&    currentSize,
69   float&            localX,
70   float&            localY,
71   float             screenX,
72   float             screenY);
73
74 /**
75  * Convert screen coordinates to local coordinates
76  * Search through the given renderTaskList to check if this entity can be converted
77  *
78  * @param[in] renderTaskList The render task list to search
79  * @param[in] worldMatrix The world matrix of this entity
80  * @param[in] currentSize The 2d bounding box for this entity
81  * @param[out] localX The local X coordinate
82  * @param[out] localY The local Y coordinate
83  * @param[in] screenX The screen X coordinate
84  * @param[in] screenY The screen Y coordinate
85  * @return true if the conversion was successful
86  */
87 bool ConvertScreenToLocalRenderTaskList(
88   const RenderTaskList& renderTaskList,
89   const Matrix&         worldMatrix,
90   const Vector3&        currentSize,
91   float&                localX,
92   float&                localY,
93   float                 screenX,
94   float                 screenY);
95
96 /**
97  * Calculate the screen position of the actor from it's node transform and anchor point
98  *
99  * @param[in] actor The actor to calculate the screen position for
100  * @param[in] bufferIndex The current event buffer index
101  * @return the screen position
102  */
103 const Vector2 CalculateActorScreenPosition(const Actor& actor, BufferIndex bufferIndex);
104
105 /**
106  * Calculate the screen extents of the actor from its node transform, anchor point and size
107  *
108  * @param[in] actor The actor
109  * @param[in] screenPosition The actor's screen position
110  * @param[in] bufferIndex The current event buffer index
111  * @return the screen extents of the actor
112  */
113 Rect<> CalculateActorScreenExtents(const Actor& actor, const Vector2& screenPosition, BufferIndex bufferIndex);
114
115 /**
116  * Convert local coordinates to screen coordinates
117  *
118  * @param[in] viewMatrix The view matrix used to display this entity
119  * @param[in] projectionMatrix The projection matrix used to display this entity
120  * @param[in] worldMatrix The world matrix of this entity
121  * @param[in] viewport The viewport used for drawing
122  * @param[in] localPosition The local position
123  * @param[out] screenX The screen X coordinate
124  * @param[out] screenY The screen Y coordinate
125  * @return true if the conversion was successful
126  */
127 bool ConvertLocalToScreen(const Matrix&   viewMatrix,
128                           const Matrix&   projectionMatrix,
129                           const Matrix&   worldMatrix,
130                           const Viewport& viewport,
131                           const Vector3&  localPosition,
132                           float&          screenX,
133                           float&          screenY);
134
135 /**
136  * Convert local coordinates to screen coordinates
137  *
138  * @param[in] renderTask The render task used to display this entity
139  * @param[in] actor The actor of this entity
140  * @param[in] worldMatrix The world matrix of this entity
141  * @param[in] localPosition The local position
142  * @param[out] screenX The screen X coordinate
143  * @param[out] screenY The screen Y coordinate
144  * @return true if the conversion was successful
145  */
146 bool ConvertLocalToScreenRenderTask(
147   const RenderTask& renderTask,
148   const Actor&      actor,
149   const Matrix&     worldMatrix,
150   const Vector3&    localPosition,
151   float&            screenX,
152   float&            screenY);
153
154 /**
155  * Convert local coordinates to screen coordinates
156  * Search through the given renderTaskList to check if this entity can be converted
157  *
158  * @param[in] renderTaskList The render task list to search
159  * @param[in] actor The actor of this entity
160  * @param[in] worldMatrix The world matrix of this entity
161  * @param[in] localPosition The local position
162  * @param[out] screenX The screen X coordinate
163  * @param[out] screenY The screen Y coordinate
164  * @return true if the conversion was successful
165  */
166 bool ConvertLocalToScreenRenderTaskList(
167   const RenderTaskList& renderTaskList,
168   const Actor&          actor,
169   const Matrix&         worldMatrix,
170   const Vector3&        localPosition,
171   float&                screenX,
172   float&                screenY);
173
174 /**
175  * Calculate the screen position of the actor from it's node transform and anchor point.
176  * It will consider rendertasklist.
177  *
178  * @param[in] actor The actor
179  * @param[in] bufferIndex The current event buffer index
180  * @return the screen extents of the actor consider camera.
181  */
182 const Vector2 CalculateActorScreenPositionRenderTaskList(const Actor& actor, BufferIndex bufferIndex);
183
184 /**
185  * Convert local coordinates to screen coordinates extent
186  *
187  * @param[in] renderTask The render task used to display this entity
188  * @param[in] actor The actor of this entity
189  * @param[in] worldMatrix The world matrix of this entity
190  * @param[in] localPosition The local position
191  * @param[out] screenExtent The screen Extent
192  * @return true if the conversion was successful
193  */
194 bool ConvertLocalToScreenExtentRenderTask(
195   const RenderTask& renderTask,
196   const Actor&      actor,
197   const Matrix&     worldMatrix,
198   const Vector3&    currentSize,
199   Rect<>&           screenExtent);
200
201 /**
202  * Convert local coordinates to screen coordinates extent
203  * Search through the given renderTaskList to check if this entity can be converted
204  *
205  * @param[in] renderTaskList The render task list to search
206  * @param[in] actor The actor of this entity
207  * @param[in] worldMatrix The world matrix of this entity
208  * @param[in] localPosition The local position
209  * @param[out] screenExtent The screen Extent
210  * @return true if the conversion was successful
211  */
212 bool ConvertLocalToScreenExtentRenderTaskList(
213   const RenderTaskList& renderTaskList,
214   const Actor&          actor,
215   const Matrix&         worldMatrix,
216   const Vector3&        currentSize,
217   Rect<>&               screenExtent);
218 /**
219  * Calculate the screen extents of the actor from its node transform, anchor point and size.
220  * It will consider rendertasklist.
221  *
222  * @param[in] actor The actor
223  * @param[in] bufferIndex The current event buffer index
224  * @return the screen extents of the actor consider camera.
225  */
226 Rect<> CalculateActorScreenExtentsRenderTaskList(const Actor& actor, BufferIndex bufferIndex);
227
228 /**
229  * Get the world transform of the actor.
230  *
231  * This calculates the world transform from scratch using only event
232  * side properties - it does not rely on the update thread to have
233  * already calculated the transform.
234  *
235  * @param[in] actor The actor to calculate the world matrix for
236  * @return The world transform matrix
237  */
238 Matrix CalculateActorWorldTransform(const Actor& actor);
239
240 /**
241  * Get the world color of the actor.
242  *
243  * This calcualtes the world color of the actor from scratch using
244  * only event side properties. It does not rely on the update thread
245  * to have already calculated the color.
246  *
247  * @param[in] actor The actor to calculate the world color for
248  * @return the world color
249  */
250 Vector4 CalculateActorWorldColor(const Actor& actor);
251
252 /**
253  * @brief Get the rotate of the actor look at specific position.
254  *
255  * @param[in] actor The actor for which to calculate the look at orientation.
256  * @param[in] target The target world position to look at.
257  * @param[in] up The up vector after target look at.
258  * @param[in] localForward The forward vector of actor when it's orientation is not applied.
259  * @param[in] localUp The up vector of actor when it's orientation is not applied.
260  * @return The orientation result of this lookAt result.
261  */
262 Quaternion CalculateActorLookAtOrientation(const Actor& actor, Vector3 target, Vector3 up, Vector3 localForward, Vector3 localUp);
263
264 } // namespace Dali::Internal
265
266 #endif // DALI_INTERNAL_EVENT_ACTORS_ACTOR_COORDS_H