#include "Spring.h"



Spring::Spring(Vertex *p1, Vertex *p2, float stiffness) {
	this->p1 = p1;
	this->p2 = p2;
	this->stiffness = stiffness;
	SbVec3f diff = p1->pos - p2->pos;
	diff *= 1.1f;
	this->initlength = diff.length();}

void Spring::Updatepoints() {
	SbVec3f diffvec = p2->pos - p1->pos;
	curlength = diffvec.length();
	diffvec.normalize();
	SbVec3f force = stiffness*(curlength - initlength)*diffvec;
	p1->addforce(force);
	p2->addforce(-force);
}

void Spring::BlowUp() {
	//increases initlenght by 10 percent
	initlength *= 1.1;
}


