Sdl_fingerdown/up/motion

Can someone point me to a working example?

I’m trying to follow testgesture.c but it seems that there is something
strange going on.

I get xres / yres at 32768 when I call SDL_GetTouch() on my FINGERDOWN
event, and this cause my coords to always be 0,0:

case SDL_FINGERDOWN:
{
SDL_Touch *t = SDL_GetTouch(e.tfinger.touchId);
int x = t.tfinger.x / t->xres,
y = t.tfinger.y / t->yres;

// -> x and y are always 0

[…]

Maybe this has something to do with the fact I’m using a logical size for
the window different from the physical one?

Tests done on iOS6, both on real device (iphone5) and simulator.–
Bye,
Gabry

I get xres / yres at 32768 when I call SDL_GetTouch() on my FINGERDOWN

event, and this cause my coords to always be 0,0:

case SDL_FINGERDOWN:
{
SDL_Touch *t = SDL_GetTouch(e.tfinger.touchId);
int x = t.tfinger.x / t->xres,
y = t.tfinger.y / t->yres;

Doing some googling I found that I have to use:

x = event.tfinger.x * screen_width / t->xres;
y = event.tfinger.y * screen_height / t->yres;

… i think testgesture.c needs an update, I tried to create a user in the
wiki to improve the documentation of this:

http://wiki.libsdl.org/moin.cgi/SDL_TouchFingerEvent

…but the user creation operation timed out, there is some problem in the
wiki? :slight_smile:

I tried the user creation both friday and today!–
Bye,
Gabry

Have you tried:

int x = int(float(event.tfinger.x) / t->xres);

Or even better:

float logicalX = float(event.tfinger.x) / t->xres;

It looks like the result is just rounding down to zero.On 19 November 2012 11:09, Gabriele Greco <gabriele.greco at darts.it> wrote:

I get xres / yres at 32768 when I call SDL_GetTouch() on my FINGERDOWN

event, and this cause my coords to always be 0,0:

case SDL_FINGERDOWN:
{
SDL_Touch *t = SDL_GetTouch(e.tfinger.touchId);
int x = t.tfinger.x / t->xres,
y = t.tfinger.y / t->yres;

Doing some googling I found that I have to use:

x = event.tfinger.x * screen_width / t->xres;
y = event.tfinger.y * screen_height / t->yres;

… i think testgesture.c needs an update, I tried to create a user in the
wiki to improve the documentation of this:

http://wiki.libsdl.org/moin.cgi/SDL_TouchFingerEvent

…but the user creation operation timed out, there is some problem in the
wiki? :slight_smile:

I tried the user creation both friday and today!


Bye,
Gabry


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

You should pay more attention to things just saying

  1. I answered your question
  2. I showed you the errors and explained why in my reply
  3. I showed you in my reply where they multiply the x and y by the width and height in the testgesture.c
  4. You never bothered checking if someone replied to your post

Gabriele Greco wrote:>

I get xres / yres at 32768 when I call SDL_GetTouch() on my FINGERDOWN event, and this cause my coords to always be 0,0:

case SDL_FINGERDOWN:
?{ ?
? ?SDL_Touch *t = SDL_GetTouch(e.tfinger.touchId);
? ?int x = t.tfinger.x / t->xres,
? ? ? ?y ?= t.tfinger.y / t->yres;

Doing some googling I found that I have to use:

x = event.tfinger.x * screen_width / t->xres;

y = event.tfinger.y * screen_height / t->yres;

… i think testgesture.c needs an update, I tried to create a user in the wiki to improve the documentation of this:?

http://wiki.libsdl.org/moin.cgi/SDL_TouchFingerEvent (http://wiki.libsdl.org/moin.cgi/SDL_TouchFingerEvent)

…but the user creation operation timed out, there is some problem in the wiki? :slight_smile:

I tried the user creation both friday and today!


Bye, ?Gabry

not sure how you even came up with this t.tfinger.x it should be your event instance e.tfinger.x

from testgesture.c

  x = ((float)event->tfinger.x)/inTouch->xres;
  y = ((float)event->tfinger.y)/inTouch->yres;

what you should have

  x = ((float)e.tfinger.x)/t->xres;
  y = ((float)e.tfinger.y)/t->yres;

then if you keep looking where it calls the draw from testgesture.c

  if(event->type == SDL_FINGERMOTION)
drawCircle(screen,x*screen->w,y*screen->h,5,col);
  else if(event->type == SDL_FINGERDOWN)
drawCircle(screen,x*screen->w,y*screen->h,-10,col); 

you notice how it multiply’s the x and y by the screen width and height giving the final x and y coordinate

or you could do

  x = ((float)e.tfinger.x)/t->xres * screen_width;
  y = ((float)e.tfinger.y)/t->yres * screen_height;

the reason for 0 is because it equals a small decimal number below 1 so an int will be either 1 or 0 so you need to multiply for the final int value or use floats.

Also note on iOS for me to get the right coordinates I seem to have needed to use the latest screen size width and height even though my width was actually 480.

  x = ((float)e.tfinger.x)/t->xres * 568;
  y = ((float)e.tfinger.y)/t->yres * 320;

Gabriele Greco wrote:> Can someone point me to a working example?

I’m trying to follow testgesture.c but it seems that there is something strange going on.

I get xres / yres at 32768 when I call SDL_GetTouch() on my FINGERDOWN event, and this cause my coords to always be 0,0:

case SDL_FINGERDOWN:
?{ ?
? ?SDL_Touch *t = SDL_GetTouch(e.tfinger.touchId);
? ?int x = t.tfinger.x / t->xres,
? ? ? ?y ?= t.tfinger.y / t->yres;

// -> x and y are always 0

[…]

Maybe this has something to do with the fact I’m using a logical size for the window different from the physical one?

Tests done on iOS6, both on real device (iphone5) and simulator.


Bye,
?Gabry

**
You should pay more attention to things just saying

  1. I answered your question
  2. I showed you the errors and explained why in my reply
  1. I showed you in my reply where they multiply the x and y by the width

and height in the testgesture.c

Yes, testgesture.c is correct, I looked at it only in the surface and the
variable names x & y made me thought they where pixel values like they are
in the (similar) MOUSEUP/DOWN events.

  1. You never bothered checking if someone replied to your post

From your reply header:

Received: by 10.112.1.7 with SMTP id 7csp350193lbi;

Tue, 20 Nov 2012 19:16:56 -0800 (PST)

I read mailing lists once per day usually, sorry if I’ve not responded
before.

Anyway I didn’t expected any reply (except for the problem with the wiki
registration) since I responded myself with a working solution (in the ML)
before anyone did.On Mon, Nov 19, 2012 at 1:14 PM, stevo5800 wrote:


Bye,
Gabry