~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/covira/snake_notv.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * snake_pick_notv.c
  3  *
  4  * Graphics free versions of snake interaction calls for Covira.
  5  *
  6  */
  7 
  8 #include <tina/all_tina.h>
  9 #include <tina/brain.h>
 10 #include <tina/brainfuncs.h>
 11 
 12 static double scale = 16.0;
 13 
 14 static Vec2 notv_snake_closest(Snake * snake, Vec2 p)
 15 {
 16     int i;
 17     double d, dmin = 1e10;
 18     Vec2 pmin;
 19     if (snake == NULL)
 20         return (p);
 21     for (i = 0; i < snake->n; i++)
 22         if ((d = vec2_dist(p, snake->p[i])) < dmin)
 23         {
 24             dmin = d;
 25             pmin = snake->p[i];
 26         }
 27     return (pmin);
 28 }
 29 
 30 static double pusher(Vec2 p, Vec2 centre, double scale)
 31 {
 32     double s;
 33 
 34     s = PI * vec2_dist(centre, p) / scale;
 35     if (s < PI)
 36         return (1.0 + cos(s));
 37     else
 38         return (0.0);
 39 }
 40 
 41 static Vec2 backproj2(Ipos pos) /* dummy */
 42 {
 43   return(vec2(ipos_x(pos), ipos_y(pos)));
 44 }
 45 
 46 static Vec2 centre, plast;
 47 void notv_snake_edit_down(Ipos pos)
 48 {
 49     Snake *snake = ims_snake_get();
 50 
 51     if (snake == NULL)
 52         return;
 53 
 54     plast = backproj2(pos);
 55     centre = snake_centroid(snake);
 56 
 57     scale = 2.0 * vec2_dist(plast, notv_snake_closest(snake, plast));
 58     scale = MAX(1.0, scale);
 59 }
 60 
 61 void notv_snake_push_drag(Ipos pos)
 62 {
 63     Vec2 dp, p;
 64     double gmax;
 65     int i, n;
 66     Snake *snake = ims_snake_get();
 67 
 68     if (snake == NULL)
 69         return;
 70 
 71     p = backproj2(pos);
 72     dp = vec2_diff(p, plast);
 73     plast = p;
 74 
 75     n = snake->n;
 76     gmax = 0.0;
 77     for (i = 0; i < n; ++i)
 78     {
 79         Vec2 q;
 80         double g;
 81 
 82         q = snake->p[i];
 83         g = pusher(q, p, scale);
 84         gmax = MAX(gmax, g);
 85     }
 86     if (gmax == 0.0)
 87         gmax = 1.0;
 88     for (i = 0; i < n; ++i)
 89     {
 90         Vec2 q;
 91         double g;
 92 
 93         q = snake->p[i];
 94         g = pusher(q, p, scale) / gmax;
 95         q = vec2_sum(q, vec2_times(g, dp));
 96         snake->p[i] = q;
 97     }
 98 }
 99 
100 void notv_snake_push_up(Ipos pos)
101 {
102     Snake *snake = ims_snake_get();
103 
104     if (snake == NULL)
105         return;
106 
107     ims_snake_changed();
108 }
109 
110 void notv_snake_shift_drag(Ipos pos)
111 {
112     Snake *snake = ims_snake_get();
113     Vec2 p, dp;
114 
115     if (snake == NULL)
116         return;
117 
118     p = backproj2(pos);
119     dp = vec2_diff(p, plast);
120     plast = p;
121     snake_shift(snake, dp);
122 }
123 
124 void notv_snake_shift_up(Ipos pos)
125 {
126     Snake *snake = ims_snake_get();
127 
128     if (snake == NULL)
129         return;
130 
131     ims_snake_changed();
132 }
133 
134 void notv_snake_zoom_drag(Ipos pos)
135 {
136     int i, n;
137     Snake *snake = ims_snake_get();
138     Vec2 p;
139     double zoom, theta;
140     Mat2 r;
141 
142     if (snake == NULL)
143         return;
144 
145     p = backproj2(pos);
146     theta = vec2_angle(vec2_diff(plast, centre), vec2_diff(p, centre));
147     zoom = vec2_dist(p, centre) / vec2_dist(plast, centre);
148     plast = p;
149 
150     r = rot2(theta);
151     n = snake->n;
152     for (i = 0; i < n; ++i)
153     {
154         Vec2 q;
155 
156         q = snake->p[i];
157         q = vec2_sum(centre,
158                      vec2_times(zoom,
159                                 mat2_vprod(r, vec2_diff(q, centre))));
160         snake->p[i] = q;
161     }
162 }
163 
164 void notv_snake_zoom_up(Ipos pos)
165 {
166     Snake *snake = ims_snake_get();
167     if (snake == NULL)
168         return;
169     ims_snake_changed();
170 }
171 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.