Pendulum::PolyChain Pendulum::positions() const { PolyChain result(weightCnt()); result[0] = math::float2(deflection(0), 0); for (int i = 1; i < weightCnt(); ++i) { float const dySq = m_lengthSq - math::sq(deflection(i) - deflection(i - 1)); float const dy = dySq <= 0.0f ? 0.0f : std::sqrt(dySq); result[i] = math::float2( deflection(i), result[i - 1].y + dy ); } return result; }
/* * map() maps a M2 x M1 source image fsource[i][j] onto an N2 x N1 target * image ftarget[i][j] with the mapping * ftarget(r) += fsource(r + d) * where the deflection d = (di, dj) is supplied by function deflection() * * we use the slightly confusing notation (i,j) -> (y, x) */ void map(float **ftarget, int N1, int N2, float **fsource, int M1, int M2, int (*deflection)(float ri, float rj, float *di, float *dj)) { int i, j, index, goodtriangle; float di, dj; vert *point[3], *basevert; /* set source image globals */ gfsource = fsource; gftarget = ftarget; gM1 = M1; gM2 = M2; for (i = 0; i < N2; i++) { gtargeti = i; for (j = 0; j < N1; j++) { gtargetj = j; gfsum = gareasum = 0.0; /* do the upper triangle */ point[0] = makevertex(j, i + 1); point[1] = makevertex(j + 1, i + 1); point[2] = makevertex(j + 1, i); goodtriangle = 1; for (index = 0; index < 3; index++) { goodtriangle *= deflection(point[index]->y, point[index]->x, &di, &dj); point[index]->y += di; point[index]->x += dj; } if (goodtriangle) { makering(&basevert, point, 3); if (globalmapmode == INVERSEMAPMODE) { garea = trianglearea(basevert); } decompose(basevert); } /* do the lower triangle */ point[0] = makevertex(j, i + 1); point[1] = makevertex(j, i); point[2] = makevertex(j + 1, i); goodtriangle = 1; for (index = 0; index < 3; index++) { goodtriangle *= deflection(point[index]->y, point[index]->x, &di, &dj); point[index]->y += di; point[index]->x += dj; } if (goodtriangle) { makering(&basevert, point, 3); if (globalmapmode == INVERSEMAPMODE) { garea = trianglearea(basevert); } decompose(basevert); } /* now add the pixel value */ if ((gareasum > 0.0) && (globalmapmode == FORWARDMAPMODE)) { ftarget[i][j] = gfsum / gareasum; } freeverts(); } } }
/* scroll of deflection */ void i_deflect(pob o) { if (o->blessing > -1) Objects[o->id].known = 1; deflection(o->blessing); }