//----------------------------------------------------------------------- internal void finishCurve(char lc) { int n; if (lc == 'c' || lc == 'C' || lc == 's' || lc == 'S') { n = 3; } else if (lc == 'q' || lc == 'Q' || lc == 't' || lc == 'T') { n = 2; } else { n = curve.size() - 1; } for (int i = 0; i < curve.size(); i += n) { if (i + 3 >= curve.size()) { break; } BezierCurve2 bc2 = new BezierCurve2(); bc2.setNumSeg(mNumSeg); bc2.addPoint(curve[i + 0]); bc2.addPoint(curve[i + 1]); bc2.addPoint(curve[i + 2]); bc2.addPoint(curve[i + 3]); Shape bc2shape = bc2.realizeShape(); //Vector2 lp = shape.getPoint(shape.getPoints().size() - 1); Vector2 lp = shape.getPoint(shape.getPointCount() - 1); //for (std::vector<Vector2>::iterator iter = bc2shape.getPoints().begin(); iter != bc2shape.getPoints().end(); iter++) for (int j = 0; j < bc2shape.getPointCount(); j++) { //if (iter == bc2shape.getPoints().begin()) if (j == 0) { //if (*iter != lp) shape.addPoint(*iter); if (bc2shape.getPointsReference()[j] != lp) { shape.addPoint(bc2shape.getPointsReference()[j]); } } else { shape.addPoint(bc2shape.getPointsReference()[j]);//shape.addPoint(*iter); } } } curve.clear(); }
void parseArcTo(bool rel, bool next) { if (next) { index++; } float rx = 0.0f; if (!parseReal(ref rx)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float ry = 0.0f; if (!parseReal(ref ry)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float x_axis_rotation = 0.0f; if (!parseReal(ref x_axis_rotation)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float large_arc_flag = 0.0f; if (!parseReal(ref large_arc_flag)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float sweep_flag = 0.0f; if (!parseReal(ref sweep_flag)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float x = 0.0f; if (!parseReal(ref x)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float y = 0.0f; if (!parseReal(ref y)) { OGRE_EXCEPT("Exception::ERR_INVALIDPARAMS", "Expecting a Real number", "parseCurveSTo"); } float RadiansPerDegree = Math.PI / 180.0f; float epx = rel ? point.x + x : x; float epy = rel ? point.y + y : y; bool largeArc = (large_arc_flag > 0); bool clockwise = (sweep_flag > 0); if (epx == point.x && epy == point.y) { return; } if (rx == 0.0f && ry == 0.0f) { point = new Vector2(epx, epy); shape.addPoint(point); return; } float sinPhi = sin(x_axis_rotation * RadiansPerDegree); float cosPhi = cos(x_axis_rotation * RadiansPerDegree); float x1dash = cosPhi * (point.x - epx) / 2.0f + sinPhi * (point.y - epy) / 2.0f; float y1dash = -sinPhi * (point.x - epx) / 2.0f + cosPhi * (point.y - epy) / 2.0f; float root; float numerator = rx * rx * ry * ry - rx * rx * y1dash * y1dash - ry * ry * x1dash * x1dash; if (numerator < 0.0) { float s = (float)sqrt(1.0f - numerator / (rx * rx * ry * ry)); rx *= s; ry *= s; root = 0.0f; } else { root = ((largeArc && clockwise) || (!largeArc && !clockwise) ? -1.0f : 1.0f) * sqrt(numerator / (rx * rx * y1dash * y1dash + ry * ry * x1dash * x1dash)); } float cxdash = root * rx * y1dash / ry; float cydash = -root * ry * x1dash / rx; float cx = cosPhi * cxdash - sinPhi * cydash + (point.x + epx) / 2.0f; float cy = sinPhi * cxdash + cosPhi * cydash + (point.y + epy) / 2.0f; float theta1 = CalculateVectorAngle(1.0f, 0.0f, (x1dash - cxdash) / rx, (y1dash - cydash) / ry); float dtheta = CalculateVectorAngle((x1dash - cxdash) / rx, (y1dash - cydash) / ry, (-x1dash - cxdash) / rx, (-y1dash - cydash) / ry); if (!clockwise && dtheta > 0) { dtheta -= 2.0f * Math.PI; } else if (clockwise && dtheta < 0) { dtheta += 2.0f * Math.PI; } int segments = (int)ceil((double)abs(dtheta / (Math.PI / 2.0f))); float delta = dtheta / segments; float t = 8.0f / 3.0f * sin(delta / 4.0f) * sin(delta / 4.0f) / sin(delta / 2.0f); float startX = point.x; float startY = point.y; BezierCurve2 bezier = new BezierCurve2(); bezier.addPoint(startX, startY); for (int i = 0; i < segments; ++i) { float cosTheta1 = cos(theta1); float sinTheta1 = sin(theta1); float theta2 = theta1 + delta; float cosTheta2 = cos(theta2); float sinTheta2 = sin(theta2); float endpointX = cosPhi * rx * cosTheta2 - sinPhi * ry * sinTheta2 + cx; float endpointY = sinPhi * rx * cosTheta2 + cosPhi * ry * sinTheta2 + cy; float dx1 = t * (-cosPhi * rx * sinTheta1 - sinPhi * ry * cosTheta1); float dy1 = t * (-sinPhi * rx * sinTheta1 + cosPhi * ry * cosTheta1); float dxe = t * (cosPhi * rx * sinTheta2 + sinPhi * ry * cosTheta2); float dye = t * (sinPhi * rx * sinTheta2 - cosPhi * ry * cosTheta2); bezier.addPoint(startX + dx1, startY + dy1); bezier.addPoint(endpointX + dxe, endpointY + dye); theta1 = theta2; startX = endpointX; startY = endpointY; } point = new Vector2(epx, epy); bezier.addPoint(point); bezier.setNumSeg(mNumSeg); std_vector <Vector2> pointList = bezier.realizeShape().getPointsReference();//getPoints(); Vector2 lp = shape.getPoint(shape.getPoints().Length - 1); //for (std::vector<Vector2>::iterator iter = pointList.begin(); iter != pointList.end(); iter++) for (int ii = 0; ii < pointList.size(); ii++) { //if (iter == pointList.begin()) if (ii == 0) { //if (*iter != lp) shape.addPoint(*iter); if (pointList[ii] != lp) { shape.addPoint(pointList[ii]); } } else { shape.addPoint(pointList[ii]);//shape.addPoint(*iter); } } }