From da425afd6199995ac7b6f23bf8744a435cc02e23 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Tue, 10 Aug 2010 12:45:52 +0100 Subject: Add property declarations to grail-types Also add accumulated values for delta and velocity properties. Signed-off-by: Henrik Rydberg --- src/grail-gestures.c | 60 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'src/grail-gestures.c') diff --git a/src/grail-gestures.c b/src/grail-gestures.c index 04ff976..c743544 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c @@ -25,6 +25,8 @@ static const float FM_SN[DIM_FM] = { 1000, 1000, 200, 1000 }; static const float FM_BAR[DIM_FM] = { 50, 50, 30, 50 }; +static const grail_time_t SAMPLE_MS = 10; +static const float EPS = 1e-5; static void compute_position(float *x, float *y, const struct touch_frame *frame) @@ -95,30 +97,39 @@ static float move_filter(const struct filter_model *m, float val) return val; } -static void move_reset(struct move_model *m, int i, float val) +static void move_reset(struct move_model *m, int i, float x, grail_time_t t) { struct filter_model *fm = &m->fm[i]; fm->raw_delta = 0; fm->action_delta = 0; - fm->value = val; - fm->original = val; + fm->velocity = 0; + fm->value = x; + fm->original = x; + fm->sample = x; + fm->sample_ms = t; m->tickle &= ~(1 << i); m->active &= ~(1 << i); } -static void move_update(struct move_model *m, int i, float val) +static void move_update(struct move_model *m, int i, float x, grail_time_t t) { struct filter_model *fm = &m->fm[i]; - fm->raw_delta = val - fm->value; + float dt = t - fm->sample_ms; + fm->raw_delta = x - fm->value; fm->action_delta = fm->raw_delta; - fm->value = val; - if (fabs(fm->raw_delta) > 0.5) + fm->velocity = dt > EPS ? (x - fm->sample) / dt : 0; + fm->value = x; + if (dt > SAMPLE_MS) { + fm->sample = x; + fm->sample_ms = t; + } + if (fabs(fm->raw_delta) > EPS) m->tickle |= (1 << i); else m->tickle &= ~(1 << i); if (m->active & (1 << i)) return; - fm->action_delta = val - fm->original; + fm->action_delta = x - fm->original; if (fabs(fm->action_delta) > fm->bar) m->active |= (1 << i); else @@ -148,24 +159,25 @@ void gru_motion(struct grail *ge, { struct gesture_recognizer *gru = ge->gru; struct move_model *m = &gru->move; + grail_time_t t = frame->time; float x, y, r, a; compute_position(&x, &y, frame); if (frame->ncreate || frame->ndestroy) { r = compute_radius(x, y, frame); a = 0; - move_reset(m, FM_X, x); - move_reset(m, FM_Y, y); - move_reset(m, FM_R, r); - move_reset(m, FM_A, a); + move_reset(m, FM_X, x, t); + move_reset(m, FM_Y, y, t); + move_reset(m, FM_R, r, t); + move_reset(m, FM_A, a, t); m->single = 0; m->multi = 0; } else if (frame->nactive < 2) { r = 0; a = 0; - move_update(m, FM_X, x); - move_update(m, FM_Y, y); - move_reset(m, FM_R, r); - move_reset(m, FM_A, a); + move_update(m, FM_X, x, t); + move_update(m, FM_Y, y, t); + move_reset(m, FM_R, r, t); + move_reset(m, FM_A, a, t); m->single = 1; m->multi = 0; } else { @@ -176,15 +188,15 @@ void gru_motion(struct grail *ge, a = m->fm[FM_A].value; a += compute_rotation(x, y, r, &gru->frame, frame); a = move_filter(&m->fm[FM_A], a); - move_update(m, FM_X, x); - move_update(m, FM_Y, y); - move_update(m, FM_R, r); - move_update(m, FM_A, a); + move_update(m, FM_X, x, t); + move_update(m, FM_Y, y, t); + move_update(m, FM_R, r, t); + move_update(m, FM_A, a, t); m->single = 0; m->multi = 1; } m->ntouch = frame->nactive; - m->time = frame->time; + m->time = t; } void gru_event(struct grail *ge, int gid, @@ -195,8 +207,10 @@ void gru_event(struct grail *ge, int gid, prop, nprop, 0); } -void gru_end(struct grail *ge, int gid, const struct move_model *m) +void gru_end(struct grail *ge, int gid, const struct move_model *m, + const grail_prop_t *prop, int nprop) { - gin_gid_end(ge, gid, m->fm[FM_X].value, m->fm[FM_Y].value, m->ntouch); + gin_gid_end(ge, gid, m->fm[FM_X].value, m->fm[FM_Y].value, m->ntouch, + prop, nprop); } -- cgit v1.2.3