DuaL Touch ANDRIOD

I’ve had this running for while now, but noticed about 5% of time it bugs out. You get odd movements.

It seems like I’m doing this wrong.

finger returns sometimes number that are not 0 or 1, thats basically when the problem occurs.

Anyone know simple way to redo this code?

if (event.type == SDL_FINGERDOWN)
{
if (event.tfinger.fingerId == 0)
{
bf1 = true;
iMouseX = Display0->GetScreenWidth() * event.tfinger.x;
iMouseY = Display0->GetScreenHeight() * event.tfinger.y;
}
else if (event.tfinger.fingerId == 1)
{
bf2 = true;
iMouseX2 = Display0->GetScreenWidth() * event.tfinger.x;
iMouseY2 = Display0->GetScreenHeight() * event.tfinger.y;
bProcess = true;
}
}

Maybe you could describe your problem and goal more specific, so we can
give you suggestion.–


< Work hard, also play hard and have fun >

    \   ^__^
     \  (oo)\_______
        (__)\       )\/\
            ||----w |
            ||     ||

-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20150425/c0e38760/attachment.pgp

With that code you’re only able to process one finger at a time. You’re using a if- and else if-statement, which means that, whenever the first finger (fingerid 0) is held, the else if-statement is never executed. The only time the else if-statement is executed is when the first finger is not held. Try changing that code into this:

Code:

if(event.type == SDL_FINGERDOWN)
{
int NumFingersHeld = 0;

// Vector2D - a class or struct specifying a 2D vector object
Vector2D ScreenSize = Display0.GetScreenSize();

if(event.tfinger.fingerId == 0)
{
	// Don't know what this do but I'll leave it here if you need it
	bf1 = true;
	
	iMouseX = ScreenSize.x * event.tfinger.x;
	iMouseY = ScreenSize.y * event.tfinger.y;

	++NumFingersHeld;
}

if(event.tfinger.fingerId == 1)
{
	// Don't know what this do but I'll leave it here if you need it
	bf2 = true;

	iMouseX2 = ScreenSize.x * event.tfinger.x;
	iMouseY2 = ScreenSize.y * event.tfinger.y;

	// Don't know what this do but I'll leave it here if you need it
	bProcess = true;

	++NumFingersHeld;
}

// Only executed when at least 2 fingers is held on the touch panel
if(NumFingersHeld >= 2)
{
	// Do stuff
}

}

Note: I returned the screen size as a 2D-vector (mathematical vector, not an std::vector) so the width and height doesn’t need to be “Get’ed” 2 times each, but that’s only optional.

I think you fixed it!, I can see the logic error, I need to face palm myself.

Both need to processed.

Thanks Dude, May the Universe give you want you truly desire.

:smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

Much Better Now,

But case event.tfinger.fingerId returns ints and floats. Still a few random pauses. But much better then before. Just been testing it the last 30 minutes.

Naith wrote:> With that code you’re only able to process one finger at a time. You’re using a if- and else if-statement, which means that, whenever the first finger (fingerid 0) is held, the else if-statement is never executed. The only time the else if-statement is executed is when the first finger is not held. Try changing that code into this:

Code:

if(event.type == SDL_FINGERDOWN)
{
int NumFingersHeld = 0;

// Vector2D - a class or struct specifying a 2D vector object
Vector2D ScreenSize = Display0.GetScreenSize();

if(event.tfinger.fingerId == 0)
{
// Don’t know what this do but I’ll leave it here if you need it
bf1 = true;

  iMouseX = ScreenSize.x * event.tfinger.x;
  iMouseY = ScreenSize.y * event.tfinger.y;

  ++NumFingersHeld;

}

if(event.tfinger.fingerId == 1)
{
// Don’t know what this do but I’ll leave it here if you need it
bf2 = true;

  iMouseX2 = ScreenSize.x * event.tfinger.x;
  iMouseY2 = ScreenSize.y * event.tfinger.y;

  // Don't know what this do but I'll leave it here if you need it
  bProcess = true;

  ++NumFingersHeld;

}

// Only executed when at least 2 fingers is held on the touch panel
if(NumFingersHeld >= 2)
{
// Do stuff
}
}

Note: I returned the screen size as a 2D-vector (mathematical vector, not an std::vector) so the width and height doesn’t need to be “Get’ed” 2 times each, but that’s only optional.

Since this is in the finger down event handling, I don’t think the “else
if” construct is wrong at all.

It may be the case that you are getting fingerId values higher than 1. Can
you give us any more details about what you are trying to do or provide
more substantial code?

Jonny DOn Sat, Apr 25, 2015 at 10:47 AM, Timodor wrote:

Much Better Now,

But case event.tfinger.fingerId returns ints and floats. Still a few
random pauses. But much better then before. Just been testing it the last
30 minutes.

Naith wrote:

With that code you’re only able to process one finger at a time. You’re
using a if- and else if-statement, which means that, whenever the first
finger (fingerid 0) is held, the else if-statement is never executed. The
only time the else if-statement is executed is when the first finger is
not held. Try changing that code into this:

Code:

if(event.type == SDL_FINGERDOWN)
{
int NumFingersHeld = 0;

// Vector2D - a class or struct specifying a 2D vector object
Vector2D ScreenSize = Display0.GetScreenSize();

if(event.tfinger.fingerId == 0)
{
// Don’t know what this do but I’ll leave it here if you need it
bf1 = true;

  iMouseX = ScreenSize.x * event.tfinger.x;
  iMouseY = ScreenSize.y * event.tfinger.y;

  ++NumFingersHeld;

}

if(event.tfinger.fingerId == 1)
{
// Don’t know what this do but I’ll leave it here if you need it
bf2 = true;

  iMouseX2 = ScreenSize.x * event.tfinger.x;
  iMouseY2 = ScreenSize.y * event.tfinger.y;

  // Don't know what this do but I'll leave it here if you need it
  bProcess = true;

  ++NumFingersHeld;

}

// Only executed when at least 2 fingers is held on the touch panel
if(NumFingersHeld >= 2)
{
// Do stuff
}
}

Note: I returned the screen size as a 2D-vector (mathematical vector, not
an std::vector) so the width and height doesn’t need to be “Get’ed” 2 times
each, but that’s only optional.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hey Jonny, look time no chat.

It’s the same issue I was going on about months ago. I got it work, it’s been working and works 95% of time. But trying to get rid of the bugs.

This is core of it, and this works 95% of time, but I think the issue “event.tfinger.fingerId == 0 or 1” this returns other values other then 0 or 1. touch 3 would return 2.

But sometimes it returns odd numbers. Depending on circumstance, which I think is what is causing these pause’s.

while ( SDL_PollEvent(&event) )
{

if (event.type ==  SDL_FINGERDOWN)
{	
	if (event.tfinger.fingerId == 0)
	{
		iMouseX = Display0->GetScreenWidth() * event.tfinger.x;
		iMouseY = Display0->GetScreenHeight() * event.tfinger.y;
	}

	if (event.tfinger.fingerId == 1)
	{
		iMouseX2 = Display0->GetScreenWidth() * event.tfinger.x;
		iMouseY2 = Display0->GetScreenHeight() * event.tfinger.y;
	}
}


if (event.type ==  SDL_FINGERMOTION)
{
	if (event.tfinger.fingerId == 0)
	{		
		iMouseX = Display0->GetScreenWidth() * event.tfinger.x;
		iMouseY = Display0->GetScreenHeight() * event.tfinger.y;
	}

	if (event.tfinger.fingerId == 1)
	{
		iMouseX2 = Display0->GetScreenWidth() * event.tfinger.x;
		iMouseY2 = Display0->GetScreenHeight() * event.tfinger.y;
	}
}

if (event.tfinger.fingerId == 1)
{
	bf2 = false; // false
	iMouseX2 = -1;
	iMouseY2 = -1;
}


if (bif (event.type == SDL_FINGERUP)
{
	if (event.tfinger.fingerId == 0 )
	{
		bf1 = false; // trure
		iMouseX = -1;
		iMouseY = -1;
	}

	bf1 == false && bf2 == false)
	{
		bFingerDown = false;
	}

Jonny D wrote:> Since this is in the finger down event handling, I don’t think the “else if” construct is wrong at all.

It may be the case that you are getting fingerId values higher than 1.?? Can you give us any more details about what you are trying to do or provide more substantial code?

Jonny D

On Sat, Apr 25, 2015 at 10:47 AM, Timodor <@Timodor (@Timodor)> wrote:

  Much Better Now, 

But case event.tfinger.fingerId returns ints and floats. Still a few random pauses. But much better then before. Just been testing it the last 30 minutes.

Naith wrote:

With that code you're only able to process one finger at a time. You're using a if- and else if-statement, which means that, whenever the first finger (fingerid 0) is held, the else if-statement is never executed. The only time the else if-statement is executed is when the first finger is not held. Try changing that code into this:




Code:

if(event.type == SDL_FINGERDOWN)
{
?? ??int NumFingersHeld = 0;

?? ??// Vector2D - a class or struct specifying a 2D vector object
?? ??Vector2D ScreenSize = Display0.GetScreenSize();

?? ??if(event.tfinger.fingerId == 0)
?? ??{
?? ??? ??// Don’t know what this do but I’ll leave it here if you need it
?? ??? ??bf1 = true;
?? ??? ??
?? ??? ??iMouseX = ScreenSize.x * event.tfinger.x;
?? ??? ??iMouseY = ScreenSize.y * event.tfinger.y;

?? ??? ??++NumFingersHeld;
?? ??}

?? ??if(event.tfinger.fingerId == 1)
?? ??{
?? ??? ??// Don’t know what this do but I’ll leave it here if you need it
?? ??? ??bf2 = true;

?? ??? ??iMouseX2 = ScreenSize.x * event.tfinger.x;
?? ??? ??iMouseY2 = ScreenSize.y * event.tfinger.y;

?? ??? ??// Don’t know what this do but I’ll leave it here if you need it
?? ??? ??bProcess = true;

?? ??? ??++NumFingersHeld;
?? ??}

?? ??// Only executed when at least 2 fingers is held on the touch panel
?? ??if(NumFingersHeld >= 2)
?? ??{
?? ??? ??// Do stuff
?? ??}
}

Note: I returned the screen size as a 2D-vector (mathematical vector, not an std::vector) so the width and height doesn’t need to be “Get’ed” 2 times each, but that’s only optional.


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

I’d suggest you not try to support 2 touches and consider rather how you’d
support any number of touches. If all you need to know about touches is
whether they are active and what the position is, then consider storing
this in a map:
std::map<SDL_FingerID, std::pair<int, int> > touches;

When you get an SDL_FINGERDOWN, add a touch to the map:
touches.insert(std::make_pair(event.tfinger.fingerId, std::make_pair(x,
y)));

When you get an SDL_FINGERUP, erase the id from the map:
touches.erase(event.tfinger.fingerId);

Motion events can be handled by std::map::find and updating the position.

From this point, you can easily limit input to two touches as needed.

Jonny DOn Saturday, April 25, 2015, Timodor wrote:

Hey Jonny, look time no chat.

It’s the same issue I was going on about months ago. I got it work, it’s
been working and works 95% of time. But trying to get rid of the bugs.

This is core of it, and this works 95% of time, but I think the issue
"event.tfinger.fingerId == 0 or 1" this returns other values other then 0
or 1. touch 3 would return 2.

But sometimes it returns odd numbers. Depending on circumstance, which I
think is what is causing these pause’s.

while ( SDL_PollEvent(&event) )
{

if (event.type == SDL_FINGERDOWN)
{
if (event.tfinger.fingerId == 0)
{
iMouseX = Display0->GetScreenWidth() * event.tfinger.x;
iMouseY = Display0->GetScreenHeight() * event.tfinger.y;
}

if (event.tfinger.fingerId == 1)
{
iMouseX2 = Display0->GetScreenWidth() * event.tfinger.x;
iMouseY2 = Display0->GetScreenHeight() * event.tfinger.y;
}
}

if (event.type == SDL_FINGERMOTION)
{
if (event.tfinger.fingerId == 0)
{
iMouseX = Display0->GetScreenWidth() * event.tfinger.x;
iMouseY = Display0->GetScreenHeight() * event.tfinger.y;
}

if (event.tfinger.fingerId == 1)
{
iMouseX2 = Display0->GetScreenWidth() * event.tfinger.x;
iMouseY2 = Display0->GetScreenHeight() * event.tfinger.y;
}
}

if (event.tfinger.fingerId == 1)
{
bf2 = false; // false
iMouseX2 = -1;
iMouseY2 = -1;
}

if (bif (event.type == SDL_FINGERUP)
{
if (event.tfinger.fingerId == 0 )
{
bf1 = false; // trure
iMouseX = -1;
iMouseY = -1;
}

bf1 == false && bf2 == false)
{
bFingerDown = false;
}

Jonny D wrote:

Since this is in the finger down event handling, I don’t think the “else
if” construct is wrong at all.

It may be the case that you are getting fingerId values higher than 1.?
Can you give us any more details about what you are trying to do or provide
more substantial code?

Jonny D

On Sat, Apr 25, 2015 at 10:47 AM, Timodor <> wrote:

Quote:

Much Better Now,

But case event.tfinger.fingerId returns ints and floats. Still a few
random pauses. But much better then before. Just been testing it the last
30 minutes.

Naith wrote:

With that code you’re only able to process one finger at a time. You’re
using a if- and else if-statement, which means that, whenever the first
finger (fingerid 0) is held, the else if-statement is never executed. The
only time the else if-statement is executed is when the first finger is not
held. Try changing that code into this:

Code:

if(event.type == SDL_FINGERDOWN)
{
? ? int NumFingersHeld = 0;

? ? // Vector2D - a class or struct specifying a 2D vector object
? ? Vector2D ScreenSize = Display0.GetScreenSize();

? ? if(event.tfinger.fingerId == 0)
? ? {
? ? ? ? // Don’t know what this do but I’ll leave it here if you need it
? ? ? ? bf1 = true;
? ? ? ?
? ? ? ? iMouseX = ScreenSize.x * event.tfinger.x;
? ? ? ? iMouseY = ScreenSize.y * event.tfinger.y;

? ? ? ? ++NumFingersHeld;
? ? }

? ? if(event.tfinger.fingerId == 1)
? ? {
? ? ? ? // Don’t know what this do but I’ll leave it here if you need it
? ? ? ? bf2 = true;

? ? ? ? iMouseX2 = ScreenSize.x * event.tfinger.x;
? ? ? ? iMouseY2 = ScreenSize.y * event.tfinger.y;

? ? ? ? // Don’t know what this do but I’ll leave it here if you need it
? ? ? ? bProcess = true;

? ? ? ? ++NumFingersHeld;
? ? }

? ? // Only executed when at least 2 fingers is held on the touch panel
? ? if(NumFingersHeld >= 2)
? ? {
? ? ? ? // Do stuff
? ? }
}

Note: I returned the screen size as a 2D-vector (mathematical vector, not
an std::vector) so the width and height doesn’t need to be “Get’ed” 2 times
each, but that’s only optional.


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org