I made some progress, but when I test, nothing happens.
To explain, I have one object obj_hud, which has the code to detect. It has a list write_list, which stores the mouse coordinates so it knows where to draw the line. This part works ok, so it will draw the lines when you hold the left mouse button, and clear the coordinates when you let go.
It has a list coor_list, which contains 26 lists (one for each letter). Each of these lists are a list of directions needed to draw its letter. So for example the first list made from "180 225 270 315 0 45 90 270", represents the letter 'a'. This is because to write an 'a' on paper, when you touch the paper with the tip of the pencil, you move left (180 degrees), then bottom left (225 degrees), then down, then bottom right, then right, then top right, then top, then down. This draws the circle, then the line on the right side of the letter. So I traced this out for each of the 26 letters, basically.

Then to keep track of which letter is being drawn, I made a grid (letter_grid), it has 3 columns and 26 rows, the 26 rows are for the letters.
column 1 = 1, if user is potentially drawing this letter; 0, if this letter can't be drawn anymore
column 2 = the number of directional values (ex. 'a' would have 8 (from above))
column 3 = which direction (relative to the mouse drawing) the user is on (ex. so for 'a', it will be a number from 0 to 7)
Initially column 1 is set to 1, and column 3 is set to 0. (for each row)
When a letter is detected, a popup message is supposed to show up saying "YES".
With this info, does anyone see the problem here?
Here is the .gm81 if anyone wants to see
http://dl.dropbox.com/u/48932382/recognize.gm81
---OBJECTS---
obj_hud - create event
write_list = ds_list_create();
coor_list = ds_list_create();
ds_list_add(coor_list,string_explode("180 225 270 315 0 45 90 270"));
ds_list_add(coor_list,string_explode("270 90 45 0 315 270 225 180 135"));
ds_list_add(coor_list,string_explode("135 180 225 270 315 0 45"));
ds_list_add(coor_list,string_explode("270 135 180 225 270 315 0"));
ds_list_add(coor_list,string_explode("0 135 180 225 270 315 0 45"));
ds_list_add(coor_list,string_explode("90 45 0 225 270 180"));
ds_list_add(coor_list,string_explode("180 225 270 315 0 45 90 270 225 180 135"));
ds_list_add(coor_list,string_explode("270 90 45 0 315 270"));
ds_list_add(coor_list,string_explode("180 225 270 315 0 45 90 135 270"));
ds_list_add(coor_list,string_explode("180 225 270 315 0 45 90 135 270 225 180 135"));
ds_list_add(coor_list,string_explode("270 90 45 225 315"));
ds_list_add(coor_list,string_explode("90 270"));
ds_list_add(coor_list,string_explode("270 90 45 0 315 45 0 315 270"));
ds_list_add(coor_list,string_explode("270 90 45 0 315 270"));
ds_list_add(coor_list,string_explode("180 225 270 315 0 45 90 135"));
ds_list_add(coor_list,string_explode("270 90 45 0 315 270 225 180 135"));
ds_list_add(coor_list,string_explode("180 225 270 315 0 45 90 270 45"));
ds_list_add(coor_list,string_explode("270 90 45 0 315"));
ds_list_add(coor_list,string_explode("180 225 270 315 270 225 180"));
ds_list_add(coor_list,string_explode("270 90 0 180"));
ds_list_add(coor_list,string_explode("270 315 0 45 90"));
ds_list_add(coor_list,string_explode("315 45"));
ds_list_add(coor_list,string_explode("270 315 0 45 315 0 45 90"));
ds_list_add(coor_list,string_explode("315 135 45 225"));
ds_list_add(coor_list,string_explode("270 315 0 45 90 270 225 180 135"));
ds_list_add(coor_list,string_explode("0 225 0"));
letter_grid = ds_grid_create(3,26);
reset();
var i; for(i=0;i<26;i+=1) ds_grid_set(letter_grid, 1, i, ds_list_size(ds_list_find_value(coor_list, i)));
obj_hud - step event
left_click = mouse_check_button_pressed(mb_left);
left_hold = mouse_check_button(mb_left);
left_release = mouse_check_button_released(mb_left);
cur_ms_x = mouse_x;
cur_ms_y = mouse_y;
if left_click {
record(write_list, cur_ms_x, cur_ms_y);
} else if left_hold {
if mouse_moved() {
record(write_list, cur_ms_x, cur_ms_y);
cur_dir = point_direction(prev_ms_x, prev_ms_y, cur_ms_x, cur_ms_y);
detect();
}
} else if left_release {
clear();
}
prev_ms_x = cur_ms_x;
prev_ms_y = cur_ms_y;
obj_hud - draw event
line_draw();
---SCRIPTS---
record
ds_list_add(argument0, argument1); ds_list_add(argument0, argument2);
mouse_moved
return cur_ms_x!=prev_ms_x or cur_ms_y!=prev_ms_y;
string_explode
var c,d,e,f;
c = argument0;
d = "";
f = ds_list_create();
while string_length(c) {
e = string_char_at(c,1);
if e == " " {
ds_list_add(f, real(d));
d = "";
} else {
d += e;
}
c = string_copy(c,2,string_length(c)-1);
}
ds_list_add(f, real(d));
return f;
line_draw
var i,j,x1,y1,x2,y2;
for (i = 0; i < ds_list_size(write_list)/2 - 1; i += 1) {
j = i * 2;
x1 = ds_list_find_value(write_list, j);
y1 = ds_list_find_value(write_list, j + 1);
x2 = ds_list_find_value(write_list, j + 2);
y2 = ds_list_find_value(write_list, j + 3);
draw_line(x1, y1, x2, y2);
}
detect
var i, state, len, k;
for(i=0;i<26;i+=1) {
if ds_grid_get(letter_grid,0,i) == 1 {
state = ds_grid_get(letter_grid,2,i);
len = ds_grid_get(letter_grid,1,i);
if len == state {
clear();
show_message("YES");
} else if state < len - 1 {
k = ang_diff(cur_dir, ds_list_find_value(ds_list_find_value(coor_list, i), state)) >= 30;
if k and ang_diff(cur_dir, ds_list_find_value(ds_list_find_value(coor_list, i), state+1)) < 30 {
ds_grid_add(letter_grid,2,i,1);
} else if !k {
} else {
ds_grid_set(letter_grid,0,i,0);
}
} else {
ds_grid_set(letter_grid,0,i,0);
}
}
}
Here is the main detecting code, it basically compares the mouse moving direction with the hardcoded letter directions. So if the user follows the list of letter directions, then it should detect that as the letter.ang_diff
return abs((argument0 + 180 - argument1) mod 360 - 180);
clear
reset(); ds_list_clear(write_list);
reset
ds_grid_set_region(letter_grid,0,0,0,25,1); ds_grid_set_region(letter_grid,2,0,2,25,0);
Edited by sneaky666, 19 February 2012 - 08:41 PM.











