Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Mouse Gestures  (Read 3927 times)
0 Members and 1 Guest are viewing this topic.
Offline smallporgies

Junior Newbie

« Posted 2013-08-18 16:51:20 »

Hi all!
Does anyone have any experience with coding mouse gestures in Java? I'm think of something along the lines of what you see in Lionhead Studio's Black & White where you can have a reasonably complex shape recognised at any size in any position in the screen. Brief googling doesn't reveal anything much so hopefully someone here has a homebrew they'd like to share or anything at all in the way of advice about writing something like this myself? Thanks in advance!
Offline Several Kilo-Bytes

Senior Devvie

Medals: 11

« Reply #1 - Posted 2013-08-18 17:34:20 »

How complex are the shapes? Some people recognize simple motions in 4 or 8 directions, convert it to a string, then use a regular expression or state machine to recognize certain sequences. ("LULULURD" matches "(LU)+RD") Handwriting recognition is similar type of problem. Many of those libraries use machine learning and use many different factors. There are open source Java libraries for simple gestures recognition and hand writing recognition.

There are medium level complexity algorithms which may be good enough if the shapes all follow a similar pattern or are constrained some how.

Search link

There is also a java.awt.dnd.MouseDragGestureRecognizer class but this is the first time I've seen it.
Offline smallporgies

Junior Newbie

« Reply #2 - Posted 2013-08-18 19:17:58 »

Hm, I was after something that could do curves but I suppose that in terms of recognising that an 8 directional implementation could do the trick. I'll also need to check relative lengths of each of the motions in the gesture.

Most of those search results bring up the same thing, which appears to be 4 directional only. I'll take a look at the code and see if I can 'upgrade' it to 8 directional - Thanks!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Several Kilo-Bytes

Senior Devvie

Medals: 11

« Reply #3 - Posted 2013-08-18 20:01:22 »

Those gestures will definitely work with the simple method, but you could get false positives and you would need to make sure everything was really different according to the algorithm. Those gestures all have long strokes, so you could use the 8 direction with filtering to ignore very short deviations so jittering would not turn a square into a circle. Or use some other filtering so "88889888" was transformed to "88888888". (See numpad keys.) If you wanted the star to work only if it self-intersected at the correct points I know some techniques, but it's probably overkill.

I also forgot to mention you could try radial menus as an alternative, but that does not seem to be what you wanted.

Let us know how it works, there does not seem to be much online for in game gestures (as opposed non-twitchy to applications like web browsers.)
Offline Jeremy
« Reply #4 - Posted 2013-08-18 20:10:43 »

I've honestly never tried this before, but maybe this is an idea worth mentioning.

You could have the user create a series of points as they attempted to invoke a gesture. Record these points.

Your gestures could be complex geometry shapes. Essentially what you would do is you would construct the area of that gesture using an Area object and a series of Shapes, then take that Area object, and copy it.

Take the copy, scale it down, place it over the original and subtract from the original. Then you have a shape that outlines this gesture with a thickness proportional to however much you scaled the copy.

Now you can see if the user's points are contained by the gesture. Ofcourse, the problem is scaling the gesture shape properly. I haven't quite figured out how you would scale it...

Anyway, just an idea. I've never done this before.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)
Offline smallporgies

Junior Newbie

« Reply #5 - Posted 2013-08-18 20:49:46 »

Thanks for the great ideas guys!
I guess at this point I should elaborate on what I'm trying to do here, which is using mouse gestures for side-scrolling melee combat, and Black and White was the best example of mouse gestures in a game that came to mind. My reason for this is to try and keep the combat more skill based (as in, the human player's prowess) as opposed to being level/gear based which I figure could make for an interesting multiplayer scenario or even as a single player campaign - also it is theoretically more immersive. It's very much a WIP so I'm trying the gestures as a proof of concept... If it doesn't work I'll try something else but that is for another thread.
In any case, sounds like there's definitely some scope here for experimentation and maybe a chance to make an open source complex-gestures library of some sort while I'm at it Wink
If there are any further ideas or interesting links do post them here! I'll go away and see what I can come up with.
Offline Abuse

JGO Ninja

Medals: 66

falling into the abyss of reality

« Reply #6 - Posted 2013-08-19 02:43:32 »

Having never attempted anything even remotely like this, I'd go with something like:

- express each target gesture as a sequence of joining angles, and relative line distances (so the overall scale of what is drawn doesn't matter).
- record the points as a path
- apply a flatten filter to the recorded path
- compare the relative line distances and joining angles of the flattened path to each of your target gestures, applying some kind of fuzzy fitness algorithm.
- tune the parameters of the path flattening, the fitness algorithm, and the design of your gestures until it works to your satisfaction.

Though as I said, I've no experience in the matter, so this approach could be completely wrong.
Offline philfrei
« Reply #7 - Posted 2013-08-19 03:58:13 »

Maybe this won't be an issue, but depending on how you collect the points (assuming use of a MouseMotionListener) and process them, it may become useful to timestamp the input data.

I ended up doing this when using the MouseMotionListener to control a Theremin (vertical for tone/volume, horizontal for pitch).

It depends on how "real time" your gesture interpreter has to be.

Just a thought.

music and music apps:
Offline jonjava
« Reply #8 - Posted 2013-08-19 04:30:23 »

This isn't a java specific question so don't let that limit your searches. One technique I'm familiar with, which is straightforward and great for shape recognition, is by chaining balls together that move in 8 directions. You can vary the frequency of the balls and the radius of balls and/or zoom in/out the whole mesh to get the amount of accuracy you need.

Offline Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #9 - Posted 2013-08-19 07:37:20 »
See the links for $N, $P, etc. I found that it works ok if the gesture is similar to a pattern, otherwise tends to have false positives.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline smallporgies

Junior Newbie

« Reply #10 - Posted 2013-08-19 12:01:39 »

Thanks for the link Nate, I'll check it out.
It sounds like there are a few techniques out there - really depends on what sort of gestures need to be recognised. It may not be a one-fits-all solution if I want to keep it super efficient (kinda necessary for live combat). I'll try to find the time over the next few nights to mock something up and post it here!
Pages: [1]
  ignore  |  Print  

EgonOlsen (76 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (258 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (160 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!