4
float dampInv = 1.0 / damp;
5
float damp1 = damp - 1;
20
float thickness = INIT_TH;
22
Gesture(int mw, int mh) {
26
path = new Vec3f[capacity];
27
polygons = new Polygon[capacity];
28
crosses = new int[capacity];
29
for (int i=0;i<capacity;i++) {
30
polygons[i] = new Polygon();
31
polygons[i].npoints = 4;
32
path[i] = new Vec3f();
53
void addPoint(float x, float y) {
55
if (nPoints >= capacity) {
56
// there are all sorts of possible solutions here,
57
// but for abject simplicity, I don't do anything.
60
float v = distToLast(x, y);
61
float p = getPressureFromVelocity(v);
62
path[nPoints++].set(x,y,p);
66
jumpDx = path[nPoints-1].x - path[0].x;
67
jumpDy = path[nPoints-1].y - path[0].y;
73
float getPressureFromVelocity(float v) {
74
final float scale = 18;
75
final float minP = 0.02;
76
final float oldP = (nPoints > 0) ? path[nPoints-1].p : 0;
77
return ((minP + max(0, 1.0 - v/scale)) + (damp1*oldP))*dampInv;
81
// pressures vary from 0...1
85
float u = 1.0 / (nPoints - 1)*TWO_PI;
86
for (int i = 0; i < nPoints; i++) {
87
pressure = sqrt((1.0 - cos(t))*0.5);
93
float distToLast(float ix, float iy) {
95
Vec3f v = path[nPoints-1];
106
// compute the polygons from the path of Vec3f's
111
float radius0, radius1;
112
float ax, bx, cx, dx;
113
float ay, by, cy, dy;
114
int axi, bxi, cxi, dxi, axip, axid;
115
int ayi, byi, cyi, dyi, ayip, ayid;
117
float dx01, dy01, hp01, si01, co01;
118
float dx02, dy02, hp02, si02, co02;
119
float dx13, dy13, hp13, si13, co13;
122
int nPathPoints = nPoints - 1;
123
int lastPolyIndex = nPathPoints - 1;
124
float npm1finv = 1.0 / max(1, nPathPoints - 1);
126
// handle the first point
129
radius0 = p0.p * thickness;
132
hp01 = sqrt(dx01*dx01 + dy01*dy01);
136
co01 = radius0 * dx01 / hp01;
137
si01 = radius0 * dy01 / hp01;
153
// handle the middle points
156
for (i = 1; i < nPathPoints; i++) {
157
taper = pow((lastPolyIndex-i)*npm1finv,tapow);
164
radius1 = Math.max(mint,taper*p1.p*thickness);
166
// assumes all segments are roughly the same length...
169
hp02 = (float) Math.sqrt(dx02*dx02 + dy02*dy02);
176
// translate the integer coordinates to the viewing rectangle
177
axi = axip = (int)ax;
178
ayi = ayip = (int)ay;
179
axi=(axi<0)?(w-((-axi)%w)):axi%w;
181
ayi=(ayi<0)?(h-((-ayi)%h)):ayi%h;
184
// set the vertices of the polygon
185
apoly = polygons[nPolys++];
186
xpts = apoly.xpoints;
187
ypts = apoly.ypoints;
188
xpts[0] = axi = axid + axip;
189
xpts[1] = bxi = axid + (int) bx;
190
xpts[2] = cxi = axid + (int)(cx = p1x + si02);
191
xpts[3] = dxi = axid + (int)(dx = p1x - si02);
192
ypts[0] = ayi = ayid + ayip;
193
ypts[1] = byi = ayid + (int) by;
194
ypts[2] = cyi = ayid + (int)(cy = p1y - co02);
195
ypts[3] = dyi = ayid + (int)(dy = p1y + co02);
197
// keep a record of where we cross the edge of the screen
199
if ((axi<=LC)||(bxi<=LC)||(cxi<=LC)||(dxi<=LC)) {
202
if ((axi>=RC)||(bxi>=RC)||(cxi>=RC)||(dxi>=RC)) {
205
if ((ayi<=TC)||(byi<=TC)||(cyi<=TC)||(dyi<=TC)) {
208
if ((ayi>=BC)||(byi>=BC)||(cyi>=BC)||(dyi>=BC)) {
212
//swap data for next time
219
// handle the last point
220
p2 = path[nPathPoints];
221
apoly = polygons[nPolys++];
222
xpts = apoly.xpoints;
223
ypts = apoly.ypoints;
227
xpts[2] = (int)(p2.x);
228
xpts[3] = (int)(p2.x);
232
ypts[2] = (int)(p2.y);
233
ypts[3] = (int)(p2.y);
239
// average neighboring points
241
final float weight = 18;
242
final float scale = 1.0 / (weight + 2);
243
int nPointsMinusTwo = nPoints - 2;
244
Vec3f lower, upper, center;
246
for (int i = 1; i < nPointsMinusTwo; i++) {
251
center.x = (lower.x + weight*center.x + upper.x)*scale;
252
center.y = (lower.y + weight*center.y + upper.y)*scale;