xamarin/urho

Urho.Application.Input.TouchEnd uncorrelated with Octree.RaycastSingle

Opened this issue · 0 comments

To cast a ray, one should get TouchEndEventArgs X and Y and divide them by Graphics.Width and Graphics.Height.
But TouchEndEventArgs uses the whole screen, including the 40 pixels height black banner on top of the screen while Graphics.Height does not.

So one should make a correction to TouchEndEventArgs.Y before the ray cast:

        private uint? StarIndex(TouchEndEventArgs e, int x, int y)
        {
            {
                //The correction to make because of the 40 pixels height Black Banner on top of the screen
                float ey = ((float)(e.Y + y) - 40f) * (float)Graphics.Height  / ((float)Graphics.Height - 40f) ;
                Ray cameraRay = camera.GetScreenRay((float)(e.X + x) / Graphics.Width, (float)ey / Graphics.Height);
                RayQueryResult? result = octree.RaycastSingle(cameraRay, RayQueryLevel.Triangle, 100, DrawableFlags.Geometry);
                if (result != null)
                {
                    return result.Value.SubObject;
                }
            }
            return null;
        }