void JSpline::GeneratePixels() { float x, y; float inc = SMALL_NUMBER; mPixels.clear(); x = mMidPoints[1].x; y = mMidPoints[1].y; Point newPt(x, y); Point extraPt; mPixels.push_back(newPt); for (int n=0; n < (int)mMidPoints.size()-3; n++) { float t = inc; while (t <= 1.0f) { PointOnCurve(newPt, t, mMidPoints[n], mMidPoints[n+1], mMidPoints[n+2], mMidPoints[n+3]); float dx = newPt.x-x; float dy = newPt.y-y; float dist = sqrtf(dx*dx + dy*dy); if (dist >= MID_POINT_THRESHOLD) { // //extraPt.x = (newPt.x+x)/2; //extraPt.y = (newPt.y+y)/2; //mPixels.push_back(extraPt); // mPixels.push_back(newPt); x = newPt.x; y = newPt.y; } t += inc; } } mCount = mPixels.size(); }
/// <summary> /// Generate spline series of points from array of keyframe points /// </summary> /// <param name="points">array of key frame points</param> /// <param name="numPoints">number of points to generate in spline between each point</param> /// <returns>array of points describing spline</returns> void interpolar(vector<Point2f> &points, vector<Point2f> &splinePoints, int numNewPoints) { int i, j, numPunOri; if (numNewPoints < 1) return; numPunOri = points.size(); splinePoints.clear(); if (numPunOri < 4) { for (i = 0 ; i < numPunOri ; i++) splinePoints.push_back(points[i]); } else { splinePoints.push_back(points[0]); for (i = 0 ; i < numPunOri - 3 ; i++) { for (j = 0 ; j < numNewPoints ; j++) { splinePoints.push_back( PointOnCurve(points[i], points[i + 1], points[i + 2], points[i + 3], ((float)1 / numNewPoints) * j) ); } } splinePoints.push_back(points[numPunOri - 2]); splinePoints.push_back(points[numPunOri - 1]); } }