Hello Guest

Author Topic: tk2dCamera and BC Gestures Library  (Read 5329 times)

hemdanw

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
tk2dCamera and BC Gestures Library
« on: November 25, 2012, 08:47:57 am »
Hello,

We recently purchased and downloaded the BC Gestures Library, hoping to use it to control our player character for a 2D game using tk2dCamera.  For this we were interested in the DragGesture script to do relative motion on a touchscreen.

However, we ran into some issues due to interactions with the tk2dCamera. The tk2dCamera applies a transformation to the camera in order to achieve pixel perfect rendering.  This appears to have interacted with the BC Gestures Library and the result is that the draggable object motion was very exaggerated and wildly uncontrollable, but works correctly when the tk2dCamera script is removed.

Experimenting with ways to fix this while keeping the tk2dCamera script, we appear to have achieved a partial fix in BaseGesture.cs ScreenToWorldPosition(), we modified the following:

Ray ray = theCamera.ScreenPointToRay( screenPos );

To the following:

Ray ray = theCamera.ScreenPointToRay( theCamera.WorldToScreenPoint(screenPos) );

This seems to have achieved a partial fix, however the draggable object in our game scene only scrolls halfway through the screen when we drag the mouse across the entire screen.  We were wondering if you could suggest a more appropriate fix. Are the transformations made by tk2dCamera all covered by theCamera.WorldToScreenPoint or are there more transformations that need to be accounted for? Or is it an entirely different transformation?

Thank you,
    hemdanw

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dCamera and BC Gestures Library
« Reply #1 on: November 25, 2012, 01:08:41 pm »
This really depends on what space BC Gestures operates in. In example 1 the function returns a world space ray. The tk2dButton uses exactly the same code to calculate a world space ray, and that definitely works.
If you switched the function as shown there, that would change how it worked, and that wouldn't work if you moved the camera, for instance.

All tk2dCamera does is it feeds a custom projection matrix. ScreenPointToRay should give you the correct ray in world space - you can verify this by Debug.DrawLine'ing the ray and looking at it in scene view. I think the problem is elsewhere.

hemdanw

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: tk2dCamera and BC Gestures Library
« Reply #2 on: November 26, 2012, 03:33:02 am »
Hi Unikron,

Thank you for the quick response. You were right, I tried your tk2dCamera example with the DragGesture script and indeed it worked. The problem turned out to be due to camera position updates in LateUpdate(). I worked around the problem and everything works now.

Thanks again,
   hemdanw