src/events/SDL_gesture.c
author Jim Grandpre <jim.tla@gmail.com>
Sun, 11 Jul 2010 01:15:39 -0400
changeset 4659 063b9455bd1a
parent 4658 454385d76845
child 4663 56a2d70de945
child 4664 317a151b79ad
permissions -rw-r--r--
Added some files I had previosuly missed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     1
/*
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     3
    Copyright (C) 1997-2010 Sam Lantinga
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     4
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
     9
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    13
    Lesser General Public License for more details.
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    14
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    16
    License along with this library; if not, write to the Free Software    Founation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    17
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    18
    Sam Lantinga
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    19
    slouken@libsdl.org
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    20
*/
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    21
#include "SDL_config.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    22
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    23
/* General mouse handling code for SDL */
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    24
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    25
#include "SDL_events.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    26
#include "SDL_events_c.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    27
#include "SDL_gesture_c.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    28
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    29
//TODO: Replace with malloc
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    30
#define MAXFINGERS 3
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    31
#define MAXTOUCHES 2
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    32
#define MAXTEMPLATES 4
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    33
#define MAXPATHSIZE 1024
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    34
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    35
#define DOLLARNPOINTS 64
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    36
#define DOLLARSIZE 256
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    37
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    38
//PHI = ((sqrt(5)-1)/2)
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    39
#define PHI 0.618033989 
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    40
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    41
typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    42
  float x,y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    43
} Point;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    44
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    45
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    46
typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    47
  Point p;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    48
  float pressure;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    49
  int id;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    50
} Finger;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    51
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    52
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    53
typedef struct {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    54
  float length;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    55
  
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    56
  int numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    57
  Point p[MAXPATHSIZE];
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    58
} DollarPath;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    59
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    60
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    61
typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    62
  Finger f;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    63
  Point cv;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    64
  float dtheta,dDist;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    65
  DollarPath dollarPath;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    66
} TouchPoint;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    67
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    68
typedef struct {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    69
  Point path[DOLLARNPOINTS];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    70
  unsigned long hash;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    71
} DollarTemplate;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    72
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    73
typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    74
  int id;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    75
  Point res;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    76
  Point centroid;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    77
  TouchPoint gestureLast[MAXFINGERS];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    78
  int numDownFingers;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    79
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
    80
  int numDollarTemplates;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    81
  DollarTemplate dollarTemplate[MAXTEMPLATES];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    82
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    83
  SDL_bool recording;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    84
} GestureTouch;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    85
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    86
GestureTouch gestureTouch[MAXTOUCHES];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
    87
int numGestureTouches = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    88
SDL_bool recordAll;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    89
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    90
int SDL_RecordGesture(int touchId) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    91
  int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    92
  if(touchId < 0) recordAll = SDL_TRUE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    93
  for(i = 0;i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    94
    if((touchId < 0) || (gestureTouch[i].id == touchId)) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    95
      gestureTouch[i].recording = SDL_TRUE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    96
      if(touchId >= 0)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    97
	return 1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    98
    }      
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
    99
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   100
  return (touchId < 0);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   101
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   102
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   103
unsigned long SDL_HashDollar(Point* points) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   104
  unsigned long hash = 5381;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   105
  int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   106
  for(i = 0;i < DOLLARNPOINTS; i++) { 
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   107
    hash = ((hash<<5) + hash) + points[i].x;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   108
    hash = ((hash<<5) + hash) + points[i].y;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   109
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   110
  return hash;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   111
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   112
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   113
int SaveTemplate(DollarTemplate *templ, FILE *fp) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   114
  int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   115
  fprintf(fp,"%lu ",templ->hash);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   116
  for(i = 0;i < DOLLARNPOINTS;i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   117
    fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   118
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   119
  fprintf(fp,"\n");
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   120
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   121
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   122
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   123
int SDL_SaveAllDollarTemplates(FILE *fp) {  
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   124
  int i,j,rtrn = 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   125
  for(i = 0; i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   126
    GestureTouch* touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   127
    for(j = 0;j < touch->numDollarTemplates; j++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   128
	rtrn += SaveTemplate(&touch->dollarTemplate[i],fp);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   129
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   130
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   131
  return rtrn;  
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   132
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   133
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   134
int SDL_SaveDollarTemplate(unsigned long gestureId, FILE *fp) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   135
  int i,j;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   136
  for(i = 0; i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   137
    GestureTouch* touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   138
    for(j = 0;j < touch->numDollarTemplates; j++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   139
      if(touch->dollarTemplate[i].hash == gestureId) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   140
	return SaveTemplate(&touch->dollarTemplate[i],fp);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   141
      }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   142
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   143
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   144
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   145
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   146
int SDL_LoadDollarTemplates(int touchId, FILE *fp) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   147
  int i,loaded = 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   148
  GestureTouch *touch = NULL;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   149
  if(touchId >= 0) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   150
    for(i = 0;i < numGestureTouches; i++)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   151
      if(gestureTouch[i].id == touchId)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   152
	touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   153
    if(touch == NULL) return -1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   154
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   155
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   156
  while(!feof(fp)) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   157
    DollarTemplate templ;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   158
    fscanf(fp,"%lu ",&templ.hash);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   159
    for(i = 0;i < DOLLARNPOINTS; i++) {		
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   160
      int x,y;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   161
      if(fscanf(fp,"%i %i ",&x,&y) != 2) break;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   162
      templ.path[i].x = x;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   163
      templ.path[i].y = y;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   164
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   165
    fscanf(fp,"\n");
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   166
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   167
    if(touchId >= 0) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   168
      if(SDL_AddDollarGesture(touch,templ)) loaded++;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   169
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   170
    else {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   171
      for(i = 0;i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   172
	if(gestureTouch[i].id == touchId) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   173
	  touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   174
	  SDL_AddDollarGesture(touch,templ);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   175
	}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   176
      }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   177
      loaded++;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   178
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   179
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   180
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   181
  return 1; 
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   182
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   183
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   184
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   185
//path is an already sampled set of points
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   186
//Returns the index of the gesture on success, or -1
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   187
int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   188
  if(inTouch == NULL) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   189
    if(numGestureTouches == 0) return -1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   190
    int i = 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   191
    for(i = 0;i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   192
      inTouch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   193
      if(inTouch->numDollarTemplates < MAXTEMPLATES) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   194
	DollarTemplate *templ = 
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   195
	  &inTouch->dollarTemplate[inTouch->numDollarTemplates];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   196
	memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   197
	templ->hash = SDL_HashDollar(templ->path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   198
	inTouch->numDollarTemplates++;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   199
      }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   200
    }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   201
    return inTouch->numDollarTemplates - 1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   202
  }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   203
    DollarTemplate *templ = 
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   204
      &inTouch->dollarTemplate[inTouch->numDollarTemplates];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   205
    memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   206
    templ->hash = SDL_HashDollar(templ->path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   207
    inTouch->numDollarTemplates++;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   208
    return inTouch->numDollarTemplates - 1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   209
  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   210
  return -1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   211
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   212
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   213
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   214
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   215
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   216
float dollarDifference(Point* points,Point* templ,float ang) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   217
  //  Point p[DOLLARNPOINTS];
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   218
  float dist = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   219
  Point p;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   220
  int i;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   221
  for(i = 0; i < DOLLARNPOINTS; i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   222
    p.x = points[i].x * cos(ang) - points[i].y * sin(ang);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   223
    p.y = points[i].x * sin(ang) + points[i].y * cos(ang);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   224
    dist += sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   225
		 (p.y-templ[i].y)*(p.y-templ[i].y));
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   226
  }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   227
  return dist/DOLLARNPOINTS;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   228
  
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   229
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   230
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   231
float bestDollarDifference(Point* points,Point* templ) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   232
  //------------BEGIN DOLLAR BLACKBOX----------------//
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   233
  //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   234
  //-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   235
  float ta = -M_PI/4;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   236
  float tb = M_PI/4;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   237
  float dt = M_PI/90;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   238
  float x1 = PHI*ta + (1-PHI)*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   239
  float f1 = dollarDifference(points,templ,x1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   240
  float x2 = (1-PHI)*ta + PHI*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   241
  float f2 = dollarDifference(points,templ,x2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   242
  while(abs(ta-tb) > dt) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   243
    if(f1 < f2) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   244
      tb = x2;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   245
      x2 = x1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   246
      f2 = f1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   247
      x1 = PHI*ta + (1-PHI)*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   248
      f1 = dollarDifference(points,templ,x1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   249
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   250
    else {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   251
      ta = x1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   252
      x1 = x2;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   253
      f1 = f2;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   254
      x2 = (1-PHI)*ta + PHI*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   255
      f2 = dollarDifference(points,templ,x2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   256
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   257
  }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   258
  /*
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   259
  if(f1 <= f2)
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   260
    printf("Min angle (x1): %f\n",x1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   261
  else if(f1 >  f2)
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   262
    printf("Min angle (x2): %f\n",x2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   263
  */
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   264
  return SDL_min(f1,f2);  
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   265
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   266
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   267
float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   268
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   269
  Point points[DOLLARNPOINTS];
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   270
  int numPoints = dollarNormalize(path,points);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   271
  int i;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   272
 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   273
  int bestDiff = 10000;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   274
  *bestTempl = -1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   275
  for(i = 0;i < touch->numDollarTemplates;i++) {
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   276
    int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   277
    if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   278
  }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   279
  return bestDiff;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   280
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   281
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   282
//DollarPath contains raw points, plus (possibly) the calculated length
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   283
int dollarNormalize(DollarPath path,Point *points) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   284
  int i;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   285
  //Calculate length if it hasn't already been done
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   286
  if(path.length <= 0) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   287
    for(i=1;i<path.numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   288
      float dx = path.p[i  ].x - 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   289
	         path.p[i-1].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   290
      float dy = path.p[i  ].y - 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   291
	         path.p[i-1].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   292
      path.length += sqrt(dx*dx+dy*dy);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   293
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   294
  }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   295
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   296
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   297
  //Resample
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   298
  float interval = path.length/(DOLLARNPOINTS - 1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   299
  float dist = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   300
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   301
  int numPoints = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   302
  Point centroid; centroid.x = 0;centroid.y = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   303
  //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   304
  for(i = 1;i < path.numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   305
    float d = sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   306
		   (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y));
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   307
    //printf("d = %f dist = %f/%f\n",d,dist,interval);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   308
    while(dist + d > interval) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   309
      points[numPoints].x = path.p[i-1].x + 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   310
	((interval-dist)/d)*(path.p[i].x-path.p[i-1].x);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   311
      points[numPoints].y = path.p[i-1].y + 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   312
	((interval-dist)/d)*(path.p[i].y-path.p[i-1].y);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   313
      centroid.x += points[numPoints].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   314
      centroid.y += points[numPoints].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   315
      numPoints++;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   316
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   317
      dist -= interval;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   318
    }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   319
    dist += d;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   320
  }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   321
  if(numPoints < 1) return 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   322
  centroid.x /= numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   323
  centroid.y /= numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   324
 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   325
  //printf("Centroid (%f,%f)",centroid.x,centroid.y);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   326
  //Rotate Points so point 0 is left of centroid and solve for the bounding box
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   327
  float xmin,xmax,ymin,ymax;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   328
  xmin = centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   329
  xmax = centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   330
  ymin = centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   331
  ymax = centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   332
  
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   333
  float ang = atan2(centroid.y - points[0].y,
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   334
		    centroid.x - points[0].x);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   335
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   336
  for(i = 0;i<numPoints;i++) {					       
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   337
    float px = points[i].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   338
    float py = points[i].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   339
    points[i].x = (px - centroid.x)*cos(ang) - 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   340
                  (py - centroid.y)*sin(ang) + centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   341
    points[i].y = (px - centroid.x)*sin(ang) + 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   342
                  (py - centroid.y)*cos(ang) + centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   343
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   344
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   345
    if(points[i].x < xmin) xmin = points[i].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   346
    if(points[i].x > xmax) xmax = points[i].x; 
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   347
    if(points[i].y < ymin) ymin = points[i].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   348
    if(points[i].y > ymax) ymax = points[i].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   349
  }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   350
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   351
  //Scale points to DOLLARSIZE, and translate to the origin
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   352
  float w = xmax-xmin;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   353
  float h = ymax-ymin;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   354
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   355
  for(i=0;i<numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   356
    points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   357
    points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   358
  }  
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   359
  return numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   360
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   361
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   362
int SDL_GestureAddTouch(SDL_Touch* touch) { 
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   363
  if(numGestureTouches >= MAXTOUCHES) return -1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   364
  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   365
  gestureTouch[numGestureTouches].res.x = touch->xres;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   366
  gestureTouch[numGestureTouches].res.y = touch->yres;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   367
  gestureTouch[numGestureTouches].numDownFingers = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   368
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   369
  gestureTouch[numGestureTouches].res.x = touch->xres;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   370
  gestureTouch[numGestureTouches].id = touch->id;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   371
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   372
  gestureTouch[numGestureTouches].numDollarTemplates = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   373
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   374
  gestureTouch[numGestureTouches].recording = SDL_FALSE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   375
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   376
  numGestureTouches++;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   377
  return 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   378
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   379
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   380
GestureTouch * SDL_GetGestureTouch(int id) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   381
  int i;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   382
  for(i = 0;i < numGestureTouches; i++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   383
    //printf("%i ?= %i\n",gestureTouch[i].id,id);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   384
    if(gestureTouch[i].id == id) return &gestureTouch[i];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   385
  }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   386
  return NULL;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   387
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   388
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   389
int SDL_SendGestureMulti(GestureTouch* touch,float dTheta,float dDist) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   390
  SDL_Event event;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   391
  event.mgesture.type = SDL_MULTIGESTURE;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   392
  event.mgesture.touchId = touch->id;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   393
  event.mgesture.x = touch->centroid.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   394
  event.mgesture.y = touch->centroid.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   395
  event.mgesture.dTheta = dTheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   396
  event.mgesture.dDist = dDist;  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   397
  return SDL_PushEvent(&event) > 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   398
}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   399
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   400
int SDL_SendGestureDollar(GestureTouch* touch,int gestureId,float error) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   401
  SDL_Event event;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   402
  event.dgesture.type = SDL_DOLLARGESTURE;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   403
  event.dgesture.touchId = touch->id;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   404
  /*
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   405
    //TODO: Add this to give location of gesture?
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   406
  event.mgesture.x = touch->centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   407
  event.mgesture.y = touch->centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   408
  */
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   409
  event.dgesture.gestureId = gestureId;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   410
  event.dgesture.error = error;  
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   411
  return SDL_PushEvent(&event) > 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   412
}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   413
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   414
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   415
int SDL_SendDollarRecord(GestureTouch* touch,int gestureId) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   416
  SDL_Event event;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   417
  event.dgesture.type = SDL_DOLLARRECORD;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   418
  event.dgesture.touchId = touch->id;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   419
  event.dgesture.gestureId = gestureId;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   420
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   421
  return SDL_PushEvent(&event) > 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   422
}
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   423
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   424
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   425
void SDL_GestureProcessEvent(SDL_Event* event)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   426
{
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   427
  if(event->type == SDL_FINGERMOTION || 
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   428
     event->type == SDL_FINGERDOWN ||
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   429
     event->type == SDL_FINGERUP) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   430
    GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   431
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   432
    //Shouldn't be possible
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   433
    if(inTouch == NULL) return;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   434
    
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   435
    
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   436
    float x = ((float)event->tfinger.x)/inTouch->res.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   437
    float y = ((float)event->tfinger.y)/inTouch->res.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   438
    int j,empty = -1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   439
    
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   440
    for(j = 0;j<inTouch->numDownFingers;j++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   441
      if(inTouch->gestureLast[j].f.id != event->tfinger.fingerId) continue;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   442
      //Finger Up
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   443
      if(event->type == SDL_FINGERUP) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   444
	inTouch->numDownFingers--;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   445
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   446
	if(inTouch->recording) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   447
	  inTouch->recording = SDL_FALSE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   448
	  Point path[DOLLARNPOINTS];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   449
	  dollarNormalize(inTouch->gestureLast[j].dollarPath,path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   450
	  int index;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   451
	  if(recordAll) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   452
	    index = SDL_AddDollarGesture(NULL,path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   453
	    int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   454
	    for(i = 0;i < numGestureTouches; i++)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   455
	      gestureTouch[i].recording = SDL_FALSE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   456
	  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   457
	  else {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   458
	    index = SDL_AddDollarGesture(inTouch,path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   459
	  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   460
	  
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   461
	  if(index >= 0) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   462
	    SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   463
	  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   464
	  else {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   465
	    SDL_SendDollarRecord(inTouch,-1);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   466
	  }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   467
	}
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   468
	else {	
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   469
	  int bestTempl;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   470
	  float error;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   471
	  error = dollarRecognize(inTouch->gestureLast[j].dollarPath,
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   472
				  &bestTempl,inTouch);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   473
	  if(bestTempl >= 0){
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   474
	    //Send Event
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   475
	    int gestureId = inTouch->dollarTemplate[bestTempl].hash;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   476
	    SDL_SendGestureDollar(inTouch,gestureId,error);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   477
	    printf("Dollar error: %f\n",error);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   478
	  }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
   479
	} 
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   480
	inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   481
	break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   482
      }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   483
      else {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   484
	float dx = x - inTouch->gestureLast[j].f.p.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   485
	float dy = y - inTouch->gestureLast[j].f.p.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   486
	DollarPath* path = &inTouch->gestureLast[j].dollarPath;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   487
	if(path->numPoints < MAXPATHSIZE) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   488
	  path->p[path->numPoints].x = x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   489
	  path->p[path->numPoints].y = y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   490
	  path->length += sqrt(dx*dx + dy*dy);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   491
	  path->numPoints++;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   492
	}
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   493
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   494
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   495
	inTouch->centroid.x += dx/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   496
	inTouch->centroid.y += dy/inTouch->numDownFingers;    
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   497
	if(inTouch->numDownFingers > 1) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   498
	  Point lv; //Vector from centroid to last x,y position
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   499
	  Point v; //Vector from centroid to current x,y position
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   500
	  lv = inTouch->gestureLast[j].cv;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   501
	  float lDist = sqrt(lv.x*lv.x + lv.y*lv.y);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   502
	  //printf("lDist = %f\n",lDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   503
	  v.x = x - inTouch->centroid.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   504
	  v.y = y - inTouch->centroid.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   505
	  inTouch->gestureLast[j].cv = v;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   506
	  float Dist = sqrt(v.x*v.x+v.y*v.y);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   507
	  // cos(dTheta) = (v . lv)/(|v| * |lv|)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   508
	  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   509
	  //Normalize Vectors to simplify angle calculation
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   510
	  lv.x/=lDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   511
	  lv.y/=lDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   512
	  v.x/=Dist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   513
	  v.y/=Dist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   514
	  float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   515
	  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   516
	  float dDist = (Dist - lDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   517
	  if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   518
	  inTouch->gestureLast[j].dDist = dDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   519
	  inTouch->gestureLast[j].dtheta = dtheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   520
	  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   521
	  //printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   522
	  //gdtheta = gdtheta*.9 + dtheta*.1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   523
	  //gdDist  =  gdDist*.9 +  dDist*.1
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   524
	  //knob.r += dDist/numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   525
	  //knob.ang += dtheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   526
	  //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   527
	  //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   528
	  SDL_SendGestureMulti(inTouch,dtheta,dDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   529
	}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   530
	else {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   531
	  inTouch->gestureLast[j].dDist = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   532
	  inTouch->gestureLast[j].dtheta = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   533
	  inTouch->gestureLast[j].cv.x = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   534
	  inTouch->gestureLast[j].cv.y = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   535
	}
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   536
	inTouch->gestureLast[j].f.p.x = x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   537
	inTouch->gestureLast[j].f.p.y = y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   538
	break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   539
	//pressure?
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   540
      }      
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   541
    }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   542
    
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   543
    if(j == inTouch->numDownFingers) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   544
      //printf("Finger Down!!!\n");
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   545
      inTouch->numDownFingers++;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   546
      inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+ 
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   547
			     x)/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   548
      inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   549
			     y)/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   550
      
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   551
      inTouch->gestureLast[j].f.id = event->tfinger.fingerId;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   552
      inTouch->gestureLast[j].f.p.x  = x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   553
      inTouch->gestureLast[j].f.p.y  = y;	
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   554
      inTouch->gestureLast[j].cv.x = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   555
      inTouch->gestureLast[j].cv.y = 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   556
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   557
      inTouch->gestureLast[j].dollarPath.length = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   558
      inTouch->gestureLast[j].dollarPath.p[0].x = x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   559
      inTouch->gestureLast[j].dollarPath.p[0].y = y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
   560
      inTouch->gestureLast[j].dollarPath.numPoints = 1;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   561
    }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   562
  }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   563
}  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   564
  
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   565
  /* vi: set ts=4 sw=4 expandtab: */
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
   566