TEFUNC void keyHandler(unsigned char key) {
	switch (key) {
		case '1': constraintSystem.setComputationAlgorithm(1); break;
		case '2': constraintSystem.setComputationAlgorithm(2); break;
		case '3': constraintSystem.setComputationAlgorithm(3); break;
		case '4': constraintSystem.setComputationAlgorithm(4); break;
		case 'a': 
			if (loop) {
				loop = false;
			} else {
				loop = true;
			}
		break;
		case 'm': 
			if (move) {
				move = false;
			} else {
				move = true;
			}
		break;
		case 'p': postStabilization = true; break;
		case 'P': postStabilization = false; break;
	}

}
TEFUNC void keyHandler(unsigned char key) {
	switch (key) {
		case '1': cs.setComputationAlgorithm(1); break;
		case '2': cs.setComputationAlgorithm(2); break;
		case '3': cs.setComputationAlgorithm(3); break;
		case '4': cs.setComputationAlgorithm(4); break;
		case 'a': integrate = true; doConstraints = true; break;
		case 'A': integrate = false; doConstraints = false; break;
		case 't': if (doTorque) {doTorque=false;} else {doTorque=true;} break;
		case 'b': 
			if (PrimaryConstraint::doesBaumgarteStabilisation()) {
				PrimaryConstraint::doBaumgarteStabilisation(false);
			} else {
				PrimaryConstraint::doBaumgarteStabilisation(true);
			}
			break;
		default:break;
		case 'p': postStabilization = true; break;
		case 'P': postStabilization = false; break;
	}
}
/**
 * \brief Start-Funktion der Testumgebung
 *
 * Diese Funktion wird einmal beim Starten der Testumgebung 
 * aufgerufen. Hier sollte alles reingeschrieben werden, 
 * was für die initialisierung der einzelnen Tests nötig ist.
 */
TEFUNC void initialize(int /*argc*/, char** /*argv*/) {
	Id id1;
	id1.setType(Id::typeBox);
	id1.setNumber(1);
	SmartPointer<RigidBody> rb = rbs.create(id1);
	
	rb->setMass(200000);
	rb->setPosition(Vector3<float>(30.0, 0.0, 0.0));
	rb->setPrevPosition(Vector3<float>(30.0, 0.0, 0.0));
	
	
	rb->setVelocity(Vector3<float>(0.00, 0.00, 0.00));
	
	//rb->setForce(Vector3<float>(0.000, 0.00, 0.00));
	rb->setForce(Vector3<float>(0.0, 0.00,0.00));
	
    
	
	Quaternion q = Quaternion();
	//q.normalize();
	rb->setOrientation(q);
	rb->setAngularVelocity(Vector3<float>(0.0, 0.0, 0.0));
	rb->setInertiaTensor((rb->getMass()/12) * 7200, (rb->getMass()/12) * 7200, (rb->getMass()/12) * 7200);
	
	//rb->setTorque(Vector3<float> (0.0, 0.00, -0.001));
 	rb->setTorque(Vector3<float> (0.0, 0.0, 0.0));	
	

	Id id2;
	id2.setType(Id::typeBox);
	id2.setNumber(2);
	SmartPointer<RigidBody> rb2 = rbs.create(id2);
	
	rb2->setMass(200);
	rb2->setPosition(Vector3<float>(-30.0, 0.0, 0.0));
	rb2->setPrevPosition(Vector3<float>(-30.0, 0.0, 0.0));
	rb2->setVelocity(Vector3<float>(0.0, 0.00, 0.00));
	
	//rb2->setForce(Vector3<float>(0.0,0.0, 0.0));
	rb2->setForce(Vector3<float>(0.0,0.0,0.0));
    
	Quaternion q2 = Quaternion();
	//q2.normalize();
	rb2->setOrientation(q2);
	rb2->setAngularVelocity(Vector3<float>(0.0, 0.0, 0.0));
	rb2->setInertiaTensor((rb2->getMass()/12) * 7200, (rb2->getMass()/12) * 7200, (rb2->getMass()/12) * 7200);
	
	//rb2->setTorque(Vector3<float> (0.0, 0.0, 0.001));
	rb2->setTorque(Vector3<float> (0.0, 0.0,0.0));
	
	Id id3;
	id3.setType(Id::typeBox);
	id3.setNumber(3);
	SmartPointer<RigidBody> rb3 = rbs.create(id3);
	
	rb3->setMass(200);
	rb3->setPosition(Vector3<float>(-90.0, 0.0, 0.0));
	rb3->setPrevPosition(Vector3<float>(-90.0, 0.0, 0.0));
	rb3->setVelocity(Vector3<float>(0.0, 0.00, 0.00));
	
	//rb3->setForce(Vector3<float>(0.0,0.0, 0.0));
	rb3->setForce(Vector3<float>(0.0,0.0,0.0));
    
	Quaternion q3 = Quaternion();
	//q2.normalize();
	rb3->setOrientation(q3);
	rb3->setAngularVelocity(Vector3<float>(0.0, 0.0, 0.0));
	rb3->setInertiaTensor((rb3->getMass()/12) * 7200, (rb3->getMass()/12) * 7200, (rb3->getMass()/12) * 7200);
	
	//rb3->setTorque(Vector3<float> (0.0, 0.0, 0.001));
	rb3->setTorque(Vector3<float> (0.0, 0.0,0.0));
	
	Id cid1;
	cid1.setType(Id::typeHingeJoint);
	cid1.setNumber(1);
	Id cid2;
	cid2.setType(Id::typeBallJoint);
	cid2.setNumber(2);
	
	Vector3 <float>  eq(-30, 0, 0);
	Vector3 <float> eq2(30, 0, 0);
	//Vector3 <float>  eu(-30, 90, 0);
	Vector3 <float>  eu(0, 0, 30);
        //Vector3 <float>  eu(10, 0, 0.0000000000000000000285);
        //Vector3 <float>  eu(10, 0, 0);
	//Vector3 <float>  eu2(30, 90, 0);
	Vector3 <float>  eu2(0, 0, 30);
	
	//cs.createBallAndSocketConstraint(cid1, rb, rb2, eq, eq2);
	cs.createHingeConstraint(cid1, rb, rb2, eq, eq2, eu, eu2);
	//cs.createBallAndSocketConstraint(cid2, rb2, rb3, eq, eq2);
	cs.createHingeConstraint(cid2, rb2, rb3, eq, eq2, eu, eu2);
	//mc1 = cs.getHingeConstraint(cid1);
	
	
	
	//cs.createBallAndSocketConstraint(cid1, rb, rb2, eq, eq2);
	cs.buildGraphs();
	
	mrb = rb;
	mrb2 = rb2;
	
	//mc1 = cs.getBallAndSocketConstraint(cid1);
	//mc2 = cs.getBallAndSocketConstraint(cid2);
	
	cs.printGraphs();
	cs.setComputationAlgorithm(1);
	cs.setTau(60);
	
 	SimonState::exemplar()->setViscositySlowdownAngular(0.7);
 	SimonState::exemplar()->setViscositySlowdownLinear(0.97);
	
	/*mc1->computeConstraint();
	
	cout << "Constraint:" << endl;
	mc1->getConstraint().show();
	cout << endl;
	cout << "ConstraintDot:" << endl;
	mc1->getConstraintDot().show();*/
	
	//SimonState::exemplar()->setGravityVector(Vec3(0,-0.00181,0));
	
}