Hello Guest

Author Topic: Mouse input offset on the second screen ?  (Read 4867 times)

DisizDream

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Mouse input offset on the second screen ?
« on: March 01, 2014, 06:22:34 pm »
Hi,

I just tried using the Basic Button prefab from tkdUI_demo but I have a problem.

I'm using two tk2d cameras, each one displaying to a different screen.
The native resolution of the game is 1920x1080 and camera1 is displayed on a 1920x1080 screen and camera2 is displayed on a 854x480 touch screen.
When I try to touch the button it doesn't work, but by randomly tapping on the screen I found it works but with a big offset :

If I put the tk2dUICamera component on :
 -the camera1, there is a horizontal and vertical offset
 -the camera2, there is a only a vertical offset

Is there some camera settings I missed to make this setup works ?

Thanks !

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Mouse input offset on the second screen ?
« Reply #1 on: March 01, 2014, 07:01:21 pm »
If the 2 cameras are working correctly and displaying the buttons correctly I would expect them to work properly. tk2d uses ScreenPointToRay to ray cast for this. Be sure your layer masks are set properly, so the ray casts don't interfere. Better yet create 2 copies of the geometry to confirm everything is working properly.

Otherwise it might be an issue with what Unity is returning - I have seen an issue on a retina mac in the past to do with Unity returning incorrect screen positions for the mouse cursor, but as far as I remember that only happened in full screen mode (can't remember if you had to toggle fullscreen to trigger it). If you aren't getting anywhere with this I recommend checking what Input.mousePosition is returning.

gtsphere

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
    • dream.create.tapp
Re: Mouse input offset on the second screen ?
« Reply #2 on: August 25, 2014, 08:07:52 pm »
I am seeing this exact issue with the latest version of tk2d and 4.3 Unity (WiiU) build. It appears the input is, for lack of better description, a mirror opposite of where you would press. So imagine a button at the top right corner, touching the bottom right corner, makes it "tap". I am digging now to see what Input.mousePosition says but I have a feeling something is inverted somewhere... I'll be back with more details but any ideas are more than welcomed!
DreamTapp.com
dream.create.tapp

gtsphere

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
    • dream.create.tapp
Re: Mouse input offset on the second screen ?
« Reply #3 on: August 25, 2014, 08:39:10 pm »
So here is some interesting stuff, inside of "tk2dUIManager.cs" I put in two debug logs, inside of:

Code: [Select]
   
tk2dUIItem RaycastForUIItem( Vector2 screenPos ) {
        int cameraCount = sortedCameras.Count;
        for (int i = 0; i < cameraCount; ++i) {
            tk2dUICamera currCamera = sortedCameras[i];
            if (currCamera.RaycastType == tk2dUICamera.tk2dRaycastType.Physics3D) {

Debug.Log("Input mouse position: " + Input.mousePosition);
Debug.Log ("Ray touch position: " + screenPos);
...

And here are the results, when running the "UI Demo" itself on the Wii U gamepad:

Top LEFT Corner (touching as far top right as possible with the stylus):
Input mouse position: (8.7, 472.0, 0.0)
Ray touch position: (8.7, 8.0)

Top RIGHT Corner:
Input mouse position: (846.0, 472.0, 0.0)
Ray touch position: (846.0, 8.0)

Bottom LEFT Corner:
Input mouse position: (8.0, 8.0, 0.0)
Ray touch position: (8.0, 472.0)

Bottom RIGHT Corner:
Input mouse position: (846.0, 8.0, 0.0)
Ray touch position: (846.0, 472.0)

Tapping the "Up Down Button" itself directly in the middle:
Input mouse position: (291.6, 321.3, 0.0)
Ray touch position: (292.2, 159.3)
 ** Note: The button did NOT respond to this touch

Tapping the complete opposite area of the "Up Down Button" on the Y axis (slightly above the "On" button) to show that the offset of the button is down there, doing this DID make the "Up Down Button" respond to the touch and it did register it:
Input mouse position: (272.2, 173.3, 0.0)
Ray touch position: (272.2, 306.7)

Hopefully this all makes sense, but you can see that there is a difference in the Y axis between the touches of what is considered the "mousePosition" versus the finger touch within ray casting.

I'm going to keep digging but hopefully this rings some bells.

Thank you!
DreamTapp.com
dream.create.tapp

gtsphere

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 5
    • View Profile
    • dream.create.tapp
Re: Mouse input offset on the second screen ?
« Reply #4 on: August 25, 2014, 09:33:05 pm »
Okay, figured this out and logging it here for anyone who needs to know this. I can't post exact code due to an NDA but the general idea is, to make this work on the GamePad, go inside of:

tk2dUITouch.cs

Change the following, replace SCREEN_HEIGHT, with the height of your screen.

Code: [Select]
   
public tk2dUITouch(Touch touch) : this()
    {
Vector2 tempLoc = new Vector2( touch.position.x, SCREEN_HEIGHT - touch.position.y );

        this.phase = touch.phase;
        this.fingerId = touch.fingerId;
this.position = tempLoc;
        this.deltaPosition = deltaPosition;
        this.deltaTime = deltaTime;
    }

Doing this converts the touch position into the proper, I think, screen space compared to the mouse position.

I hope this helps someone else!
DreamTapp.com
dream.create.tapp