Touch VelocityTracker

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

Touch VelocityTracker

Postby BurningHand » Wed May 25, 2011 1:14 pm

Oops, I've been meaning to put this over in the contributions section and totally forgot.

Anyway this is my implementation of VelocityTracker, which is part of a multi-touch gesture detector I am working on (although I've not had much time lately).

http://www.nexsoftware.net/uploads/velocity/velocity-desktop.zip

And the desktop and android compiled versions:

http://www.nexsoftware.net/uploads/velocity/velocity-desktop.jar
http://www.nexsoftware.net/uploads/velocity/velocity-android.apk

I need to get some license stuff in there, but for now just know it's apache license 2 (like gdx)

This thread very well might turn into the gesture detector thread when I get to it, since this is part of that.

Anyway feel free to pick it apart, let me where it can be improved, etc...
IRC: nexsoftware / mobidevelop; GitHub: MobiDevelop;
BurningHand
 
Posts: 2812
Joined: Mon Oct 25, 2010 4:35 am

Re: Touch VelocityTracker

Postby steveyO » Wed May 25, 2011 8:30 pm

This is pretty cool BurningHand. I integrated it into my game a few nights ago and works perfectly (not to mention easy as Pi to integrate). I use it to scroll around my TMX map and I set my camera position based on the returned X and Y velocities from the tracker (and setting them to 0 if a x or y boundry is crossed)! So far haven't come accross a single issue (have tested on 3 different devices flawlessly) so extremely gratefull 8-)

One issue that I have though and am sure others will (not related to your code though, more of a general maths/physics issue) is knowing the best and most efficient formula to use to bring the velocities to a smooth halt (similar to when you touch scroll in your mobile's browser). Am going to try a few over the w/e (circular/parabolic motion/regular easing?) and will post the best solution, unless someone else has the answer ;)
Grafixator - 2D Games Editor + Random Graphics Generator
http://www.grafixator.com
steveyO
 
Posts: 80
Joined: Mon May 02, 2011 7:47 pm
Location: Netherlands

Re: Touch VelocityTracker

Postby mzechner » Thu May 26, 2011 9:32 am

simple damping of both velocity components in x/y will do the trick. Say you want to reduce your velocity by 20% each frame you can do something like this (code is only for x-axis):

Code: Select all
decay = 0.2f;
velocityX = velocityX - (velocityX * decay) * Gdx.graphics.getDeltaTime();


Do the same on y, tweak the decay and away you go :)
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: Touch VelocityTracker

Postby BurningHand » Thu May 26, 2011 2:49 pm

That would have been my suggestion as well.
IRC: nexsoftware / mobidevelop; GitHub: MobiDevelop;
BurningHand
 
Posts: 2812
Joined: Mon Oct 25, 2010 4:35 am

Re: Touch VelocityTracker

Postby steveyO » Thu May 26, 2011 8:02 pm

Thanks for the code. I was using cameraVelocityX *= 0.975 before (which worked pretty well) but this is ever so slightly smoother. Apologies for going off topic slightly.
Grafixator - 2D Games Editor + Random Graphics Generator
http://www.grafixator.com
steveyO
 
Posts: 80
Joined: Mon May 02, 2011 7:47 pm
Location: Netherlands


Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest