package clothSimulator;

public class XPinnedConstraint extends PinnedConstraint {

	//the desired value of the xcoordinate of the pinned particle
	double xPinPos;

	
	public XPinnedConstraint(Particle p, double pos) {
		super(p, pos);
		// TODO Auto-generated constructor stub
		this.p1=p;
		this.xPinPos=pos;
		this.ParticleList().add(p1);
	}

	@Override
	public void updateCurrent_g() {
		// TODO Auto-generated method stub
		g= this.p1.p.x-xPinPos;
	}
	
	@Override
	public void updateCurrent_G(){
		Gp1x=1;
		Gp1y=0;
		Gp1z=0;
	}
	
	//For an X-Pinning constraint, the inner product of a row in the Gdot matrix  with a vector just picks
	//out the element of the matrix at the index which is equal to the index of the pinned particle plus 0 (plus 1 
	//for a y-pin constraint, plus 2 for a z-pin constraint).
	@Override
	public double GiDot(double[] in) {
		// TODO Auto-generated method stub
		return in[this.p1.getIndex()*3];
	}
	
	//in the case of a pinning constraint Gp1x is just 1...the others are zero...do I even need to multiply by
	//Gp1x?...
	@Override
	public void GtransiDot(double[] in, double[] out) {
		// TODO Auto-generated method stub
		out[this.p1.getIndex()*3]+= this.Gp1x*in[this.getCLIndex()];
	}
	
}
