1 #ifndef DALI_INTERNAL_EVENT_ACTORS_ACTOR_COORDS_H
2 #define DALI_INTERNAL_EVENT_ACTORS_ACTOR_COORDS_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 namespace Dali::Internal
30 * Convert screen coordinates to local coordinates
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
43 bool ConvertScreenToLocal(const Matrix& viewMatrix,
44 const Matrix& projectionMatrix,
45 const Matrix& worldMatrix,
46 const Vector3& currentSize,
47 const Viewport& viewport,
54 * Convert screen coordinates to local coordinates
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
65 bool ConvertScreenToLocalRenderTask(
66 const RenderTask& renderTask,
67 const Matrix& worldMatrix,
68 const Vector3& currentSize,
75 * Convert screen coordinates to local coordinates
76 * Search through the given renderTaskList to check if this entity can be converted
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
87 bool ConvertScreenToLocalRenderTaskList(
88 const RenderTaskList& renderTaskList,
89 const Matrix& worldMatrix,
90 const Vector3& currentSize,
97 * Calculate the screen position of the actor from it's node transform and anchor point
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
103 const Vector2 CalculateActorScreenPosition(const Actor& actor, BufferIndex bufferIndex);
106 * Calculate the screen extents of the actor from its node transform, anchor point and size
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
113 Rect<> CalculateActorScreenExtents(const Actor& actor, const Vector2& screenPosition, BufferIndex bufferIndex);
116 * Convert local coordinates to screen coordinates
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
127 bool ConvertLocalToScreen(const Matrix& viewMatrix,
128 const Matrix& projectionMatrix,
129 const Matrix& worldMatrix,
130 const Viewport& viewport,
131 const Vector3& localPosition,
136 * Convert local coordinates to screen coordinates
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
146 bool ConvertLocalToScreenRenderTask(
147 const RenderTask& renderTask,
149 const Matrix& worldMatrix,
150 const Vector3& localPosition,
155 * Convert local coordinates to screen coordinates
156 * Search through the given renderTaskList to check if this entity can be converted
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
166 bool ConvertLocalToScreenRenderTaskList(
167 const RenderTaskList& renderTaskList,
169 const Matrix& worldMatrix,
170 const Vector3& localPosition,
175 * Calculate the screen position of the actor from it's node transform and anchor point.
176 * It will consider rendertasklist.
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.
182 const Vector2 CalculateActorScreenPositionRenderTaskList(const Actor& actor, BufferIndex bufferIndex);
185 * Convert local coordinates to screen coordinates extent
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
194 bool ConvertLocalToScreenExtentRenderTask(
195 const RenderTask& renderTask,
197 const Matrix& worldMatrix,
198 const Vector3& currentSize,
199 Rect<>& screenExtent);
202 * Convert local coordinates to screen coordinates extent
203 * Search through the given renderTaskList to check if this entity can be converted
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
212 bool ConvertLocalToScreenExtentRenderTaskList(
213 const RenderTaskList& renderTaskList,
215 const Matrix& worldMatrix,
216 const Vector3& currentSize,
217 Rect<>& screenExtent);
219 * Calculate the screen extents of the actor from its node transform, anchor point and size.
220 * It will consider rendertasklist.
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.
226 Rect<> CalculateActorScreenExtentsRenderTaskList(const Actor& actor, BufferIndex bufferIndex);
229 * Get the world transform of the actor.
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.
235 * @param[in] actor The actor to calculate the world matrix for
236 * @return The world transform matrix
238 Matrix CalculateActorWorldTransform(const Actor& actor);
241 * Get the world color of the actor.
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.
247 * @param[in] actor The actor to calculate the world color for
248 * @return the world color
250 Vector4 CalculateActorWorldColor(const Actor& actor);
253 * @brief Get the rotate of the actor look at specific position.
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.
262 Quaternion CalculateActorLookAtOrientation(const Actor& actor, Vector3 target, Vector3 up, Vector3 localForward, Vector3 localUp);
264 } // namespace Dali::Internal
266 #endif // DALI_INTERNAL_EVENT_ACTORS_ACTOR_COORDS_H