Added RenderTask WorldToViewport coordinates
[platform/core/uifw/dali-core.git] / dali / internal / event / render-tasks / render-task-impl.cpp
index a64d4ea..35e5938 100644 (file)
@@ -29,6 +29,7 @@
 #include <dali/internal/event/actors/camera-actor-impl.h>
 #include <dali/internal/event/common/property-helper.h>
 #include <dali/internal/event/common/stage-impl.h>
+#include <dali/internal/event/common/projection.h>
 #include <dali/internal/event/images/frame-buffer-image-impl.h>
 #include <dali/internal/update/nodes/node.h>
 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
@@ -54,9 +55,9 @@ namespace // For internal properties
 
 //              Name                 Type     writable animatable constraint-input  enum for index-checking
 DALI_PROPERTY_TABLE_BEGIN
-DALI_PROPERTY( "viewport-position",  VECTOR2,    true,    true,    true,    Dali::RenderTask::Property::VIEWPORT_POSITION )
-DALI_PROPERTY( "viewport-size",      VECTOR2,    true,    true,    true,    Dali::RenderTask::Property::VIEWPORT_SIZE     )
-DALI_PROPERTY( "clear-color",        VECTOR4,    true,    true,    true,    Dali::RenderTask::Property::CLEAR_COLOR       )
+DALI_PROPERTY( "viewportPosition",   VECTOR2,    true,    true,    true,    Dali::RenderTask::Property::VIEWPORT_POSITION )
+DALI_PROPERTY( "viewportSize",       VECTOR2,    true,    true,    true,    Dali::RenderTask::Property::VIEWPORT_SIZE     )
+DALI_PROPERTY( "clearColor",         VECTOR4,    true,    true,    true,    Dali::RenderTask::Property::CLEAR_COLOR       )
 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
 
 // Signals
@@ -413,6 +414,40 @@ bool RenderTask::IsSystemLevel() const
   return mIsSystemLevel;
 }
 
+bool RenderTask::WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const
+{
+  CameraActor* cam = GetCameraActor();
+
+  Vector4 pos(position);
+  pos.w = 1.0;
+
+  Vector4 viewportPosition;
+
+  Viewport viewport;
+  GetViewport( viewport );
+
+  bool ok = ProjectFull(pos,
+                        cam->GetViewMatrix(),
+                        cam->GetProjectionMatrix(),
+                        viewport.x,
+                        viewport.y,
+                        viewport.width,
+                        viewport.height,
+                        viewportPosition);
+  if(ok)
+  {
+    viewportX = viewportPosition.x;
+    viewportY = viewportPosition.y;
+  }
+
+  return ok;
+}
+
+bool RenderTask::ViewportToLocal(Actor* actor, float viewportX, float viewportY, float &localX, float &localY) const
+{
+  return actor->ScreenToLocal( *this, localX, localY, viewportX, viewportY );
+}
+
 SceneGraph::RenderTask* RenderTask::CreateSceneObject()
 {
   // This should only be called once, with no existing scene-object