Mise en cache de l'inverse des masses
This commit is contained in:
		
							parent
							
								
									a99f1ccd0a
								
							
						
					
					
						commit
						b2e3c5f6cc
					
				|  | @ -18,6 +18,7 @@ private: | |||
|     sf::VertexArray velocityLine; | ||||
| 
 | ||||
|     float mass; | ||||
|     float inv_mass; | ||||
|     float charge; | ||||
|     float restitution; | ||||
|     int layer; | ||||
|  | @ -80,6 +81,11 @@ public: | |||
|      */ | ||||
|     float getMass(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Récupère l'inverse de la masse de l'objet (en cache) | ||||
|      */ | ||||
|     float getMassInvert(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Modifie la masse de l'objet | ||||
|      */ | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ Object::Object(float x, float y) : | |||
|     acceleration(0, 0), velocity(0, 0), position(x, y), | ||||
|     accelerationLine(sf::Lines, 2), | ||||
|     velocityLine(sf::Lines, 2), | ||||
|     mass(1.f), charge(0.f), restitution(0.f), layer(10) {} | ||||
|     mass(1.f), inv_mass(1.f), charge(0.f), restitution(0.f), layer(10) {} | ||||
| 
 | ||||
| sf::Vector2f Object::getForces(EngineState& state) { | ||||
|     sf::Vector2f forces(0, 0); | ||||
|  | @ -72,8 +72,23 @@ float Object::getMass() { | |||
|     return mass; | ||||
| } | ||||
| 
 | ||||
| float Object::getMassInvert() { | ||||
|     if (inv_mass >= 0) { | ||||
|         return inv_mass; | ||||
|     } | ||||
| 
 | ||||
|     if (mass == 0) { | ||||
|         inv_mass = 0; | ||||
|         return inv_mass; | ||||
|     } | ||||
| 
 | ||||
|     inv_mass = 1 / mass; | ||||
|     return inv_mass; | ||||
| } | ||||
| 
 | ||||
| void Object::setMass(float set_mass) { | ||||
|     mass = set_mass; | ||||
|     inv_mass = -1.f; | ||||
| } | ||||
| 
 | ||||
| float Object::getCharge() { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue