void
CQIllustratorShape::
movePointTo(const CQIllustratorShapeControlPoint *point, const CPoint2D &pos)
{
  CQIllustratorShapeControlPoint *point1 = point->dup();

  point1->movePointTo(this, pos);

  setControlPoint(point1);

  delete point1;
}
void WarpPerspectiveBilinear::moveControlPoint(unsigned index, const Vec2f &shift)
{
	// depending on index, move perspective or bilinear control point
	if( isCorner( index ) ) {
		// perspective: simply move the control point
		mWarp->moveControlPoint( convertIndex( index ), shift );
	}
	else {
		// bilinear: transform control point from normalized screen space to warped space
		Vec2f pt = getControlPoint(index);
		setControlPoint(index, pt + shift);
	}
}
Beispiel #3
0
void Warp::mouseDrag( cinder::app::MouseEvent &event )
{
	if( !sIsEditMode ) return;
	if( mSelected >= mPoints.size() ) return;

	vec2 m( event.getPos() );
	vec2 p( m.x - mOffset.x, m.y - mOffset.y );

	// set control point in normalized screen space
	setControlPoint( mSelected, p / mWindowSize );

	mIsDirty = true;

	event.setHandled( true );
}
void ofxPuppetInteractive::mousePressed(ofMouseEventArgs& e){
	float distance = getNearestVertex(deformedMesh, ofVec2f(e.x, e.y), selectedVertex);
	if(distance < selectionRadius) {
		if(e.button == 0) {
			selected = true;
			setControlPoint(selectedVertex);
		} else if(e.button == 2) {
			if(controlPoints.find(selectedVertex) != controlPoints.end()) {
				removeControlPoint(selectedVertex);
			}
		}
	} else {
		selected = false;
	}
}
void
CQIllustratorShape::
movePointBy(const CQIllustratorShapeControlPoint *point, const CPoint2D &d)
{
  checkoutShape(CQIllustratorData::ChangeType::GEOMETRY);

  CQIllustratorShapeControlPoint *point1 = point->dup();

  point1->movePointBy(this, d);

  setControlPoint(point1);

  delete point1;

  checkinShape(CQIllustratorData::ChangeType::GEOMETRY);
}
void ofxPuppetInteractive::mouseDragged(ofMouseEventArgs& e){
	if(selected) {
		setControlPoint(selectedVertex, ofVec2f(e.x, e.y));
	}
}
void ofxPuppet::setControlPoint(int i) {
	setControlPoint(i, deformedMesh.getVertex(i));
}
Beispiel #8
0
void HexEdge::calcArcControlPointFromCenter(const double pac[3], double radius)
{
    if(edgeType!=ARC)
        return;
    double pc0[3], pc1[3];
    double R=radius;
    globalVertices->GetPoint(vertIds->GetId(0),pc0); //tail
    globalVertices->GetPoint(vertIds->GetId(1),pc1); //head
    double arcp[3];

    //calc radius as average of |c -p0| and |c -p1|
    if(radius==0.0)
    {

        calcParametricPointOnArc(0.5,pac,arcp);
    }
    else
    {
        //use the secant method to calculate
        //initial guesses
        double xn2,xn1,xn; //x_{n-2}=x0,x_{n-1}=x1,x_n
        if(R >0)
        {
            xn2=1.005;
            xn1=1.01;
        }
        else
        {
            xn2=0.995;
            xn1=0.99;
            R=-R;
        }
        //secant method at most 1000 iterations
        double tol = 1e-12;
        double f=1.0;
        for(int i =0;i<1000 && f/R>tol;i++)
        {
            xn = xn1 - secF(R,pac,xn1) *
                    (xn1-xn2) /
                    (secF(R,pac,xn1)-secF(R,pac,xn2));
            f=secF(R,pac,xn);
            xn2=xn1;
            xn1=xn;
            //std::cout << "iter:" << i <<", f=" << f << ", xn=" << xn << std::endl;

        }
        double w[3],midp[3];
        //midp
        vtkMath::Add(pc0,pc1,midp);
        vtkMath::MultiplyScalar(midp,0.5);

        //w
        vtkMath::Subtract(midp,pac,w);
        vtkMath::MultiplyScalar(w,xn);

        //arcp_n
        vtkMath::Add(pac,w,arcp);
        //std::cout << "radius is: " << secF(R,pac,xn)+R<<std::endl;
    }

    //std::cout << "arc (" << arcp[0] <<" " << arcp[1] <<" " << arcp[2] <<")" << std::endl;
    setControlPoint(0,arcp);
}