Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

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

Open
pldeschamps opened this issue Mar 25, 2020 · 0 comments
Open

Comments

@pldeschamps
Copy link

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;
        }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant