Exact planeclipping for actor's hit algorithm 67/265767/5
authorEunki Hong <eunkiki.hong@samsung.com>
Thu, 28 Oct 2021 07:11:27 +0000 (00:11 -0700)
committerEunki Hong <eunkiki.hong@samsung.com>
Thu, 28 Oct 2021 12:18:11 +0000 (05:18 -0700)
rayOriginLocal is difference vector betwwen the actor and the Camera(==rayOrigin).
ActorTest API's distance value is the real euclidean distance between rayOrigin and actor.
But we only need difference vector's z-axis value to clipping by View Space Plane.

So we get hitPointWorld and multiply ViewMatrix (get from renderTask's camera actor)
and get z-coordinate value at Camera Space.

Change-Id: I644fc5e9b306423d6fa58f92e492a2a7508047a6
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali/internal/event/events/hit-test-algorithm-impl.cpp

index 1576efe..397f2c5 100644 (file)
@@ -193,7 +193,13 @@ HitActor HitTestWithinLayer(Actor&                                     actor,
       // Finally, perform a more accurate ray test to see if our ray actually hits the actor.
       if(rayTest.ActorTest(actor, rayOrigin, rayDir, hitPointLocal, distance))
       {
-        if(distance >= nearClippingPlane && distance <= farClippingPlane)
+        // Calculate z coordinate value in Camera Space.
+        const Matrix&  viewMatrix = renderTask.GetCameraActor()->GetViewMatrix();
+        const Vector4& hitDir = Vector4(rayDir.x * distance, rayDir.y * distance, rayDir.z * distance, 0.0f);
+        const float    cameraDepthDistance = (viewMatrix * hitDir).z;
+
+        // Check if cameraDepthDistance is between clipping plane
+        if(cameraDepthDistance >= nearClippingPlane && cameraDepthDistance <= farClippingPlane)
         {
           // If the hit has happened on a clipping actor, then add this clipping depth to the mask of hit clipping depths.
           // This mask shows all the actors that have been hit at different clipping depths.