コード例 #1
0
ファイル: Forces.cpp プロジェクト: Secumfex/AniSimProjekt
void GravitationalForce::apply_fun(float d_t){
	for (unsigned int i = 0; i < mInfluencedPhysics.size()-1; i++){
		Physics* lhs = mInfluencedPhysics[i];
		for (unsigned int j = i+1 ; j < mInfluencedPhysics.size(); j++){
			Physics* rhs = mInfluencedPhysics[j];
			Vector3 distanceVector = rhs->getPosition()-lhs->getPosition();
			float distance = distanceVector.length();
			//Distanz in Ordnung
			if (distance < getMaxDistance() && distance >= 1.0){
				if(distance < 1){
					distance = 1;
				}
				distanceVector.normalize();
				//Anziehungskraft berechnen
				float force = mScale * (rhs->getMass()*lhs->getMass() / (distance*distance));
				//Anziehungskraft in Ordnung
				if (force > getMinForce()){
					Vector3 Rhs_forceVector = distanceVector;
					Rhs_forceVector *= force;
					//Anziehungskraft um d_t skaliert anwenden
					lhs->applyForce(Rhs_forceVector*d_t);
					Vector3 Lhs_forceVector = (-1.0) * distanceVector;
					Lhs_forceVector *= force;
					//Anziehungskraft um d_t skaliert anwenden
					rhs->applyForce(Lhs_forceVector*d_t);
				}
			}
		}
	}
}
コード例 #2
0
ファイル: Forces.cpp プロジェクト: Secumfex/AniSimProjekt
void DampedSpring::apply_fun(float d_t){
	for (unsigned int i = 0; i < mPairs.size(); i++){
		Physics* lhs = mInfluencedPhysics[mPairs[i].i];
		Physics* rhs = mInfluencedPhysics[mPairs[i].j];

		Vector3 pos_lhs = lhs->getPosition();
		Vector3 pos_rhs = rhs->getPosition();
		Vector3 pos_dif = (pos_rhs-pos_lhs);
		Vector3 vel_dif = rhs->getVelocity()-lhs->getVelocity();
		float pos_dif_length = pos_dif.length();

		//Tension --> "Gespanntheit" Berücksichtigt Länge der Feder in Ruheposition
		float tension = pos_dif_length-mRestLength;
		
		Vector3 f_b = pos_dif;
		f_b.normalize();
		f_b *= (mSpringConstant * tension + mDampConstant * ((vel_dif * pos_dif) / pos_dif_length))*d_t;
		Vector3 f_a = (-1.0) * f_b;
		
		lhs->applyForce(f_b);
		rhs->applyForce(f_a);
	}
}