Need ideas for multiple Finger tapping detection

I am trying to detect if the user is using one, two or 3 fingers tapping continuosly on one side of the screen. I have been able to come up with some code to detect the difference between 1 and 2 fingers but I am having a hard time with 3.

What I did is to record the location of the touch and see if the delta to the next touch is more than 30 px. if it is that means that the user is using more than one finger to tap.

Anyone has any ideas they want to share?

Thanks [import]uid: 8192 topic_id: 3914 reply_id: 303914[/import]

Yes.
Use a Lua “sparse” table for registering each touch. This will basically create a “cluster” where positions that are not “nil” in the table represent other touches.

One of the major advantages of Lua is that it does not use memory for nil elements in a table.
So for instance, if a single value in Lua takes 12 bytes (can’t remember the exact value):

[lua]local sparse_table = {[5]=1,[10000]=1}[/lua]

the above table will take 12*2 bytes in memory + the hash for the table. Rather than 12*10000 bytes as with any other language. [import]uid: 5750 topic_id: 3914 reply_id: 12349[/import]

If you dare to try and complete the actual implementation of this method… let me know if it works. :slight_smile:
The following is just a basic structure to give the idea:

[lua]touches = {}
grid = {size = 0.05} – 1/20th screen size

grid.gx = 320*grid.size – i.e. grid size = 16 x 24 in portrait mode
grid.gy = 480*grid.size
local function registerTouch(evt) – to be implemented in actual multi-touch environment

local nx,ny = math.ceil(evt.x * grid.size), math.ceil(evt.y * grid.size) – converts to grid size
local curgrid = ((ny - 1)*grid.gx) + nx – linearizes coordinates to a single cell number

if evt.phase ~= “ended” then
if not touches[curgrid] then
touches[curgrid] = true – put whatever you want/need
end
else
touches[curgrid] = nil
end
end

– at this point you simply count touches…
– but you need to count for pairs() or ipairs() of the table[/lua]

This basically represents the whole screen as a grid that is grid.size coarse. Coordinates of each touch are “linearized” and coarsed based on the grid parameters - otherwise you should have used a bi-dimensional array.
So, if a “cell” in the grid is already busy, it does not register the new touch. So the count of touches stays the same. If a touch on a given cell is “ended” then it removes the state from the touches table.

It should be easy enough to generalize for multi-touch. (?!) [import]uid: 5750 topic_id: 3914 reply_id: 12356[/import]

Wow. Let me think about it for a little while before I dare! Do you know how to get the touchcount? i can’t seem to find a way. Is there a table that I can get the # from maybe? [import]uid: 8192 topic_id: 3914 reply_id: 12357[/import]

Well, actually the system provided gives you a way for counting actual active touches, by simply counting elements in the “touches” table. You can attach a function to enterFrame in order to update the count at every frame.

I was also thinking about using event.id, since it’s unique for a single touch in a multitouch environment. If multi-touch within Corona already performs a positional check, we could write something this simple:

[lua]touches = {}

local function registerTouch(evt)
if evt.phase ~= “ended” then
touches[evt.id] = true
else
touches[evt.id] = nil
end
end

– then count the touches table…[/lua]

…which is more what you asked for (i.e. knowing how many touches are active…rather than their position (?!) Excluding one half of the screen is clearly trivial.)
Since I’ve not worked with Corona multitouch yet… testing is left up to you! :wink:

[import]uid: 5750 topic_id: 3914 reply_id: 12358[/import]