Before you learn about Force Impulse Torque , take a look at setlinearvelocity,setangularvelocity
One is the line speed, one is the angular velocity.
It's easy to understand. Set the body's line speed and angular velocity
Line Speed Const BTVECTOR3 & getlinearvelocity () constvoid setlinearvelocity (const BTVECTOR3 &lin_vel)//angular Speed const BtV Ector3 & Getangularvelocity () constvoid setangularvelocity (const BTVECTOR3 &ang_vel)
Now to understand force
void Applycentralforce (const BTVECTOR3 &force) void Applyforce (const BTVECTOR3 &force, const BTVECTOR3 &REL_ Pos
Applycentralforce provides a force to the body to view the source code
void Applycentralforce (const btvector3& force) {<span style= "white-space:pre" ></span>m_totalforce + = Force*m_linearfactor;}
On the basis of the original force of the body and add Force *m_linearfactor , as for this m_ Linearfactor
void Setlinearfactor (const btvector3& linearfactor) {m_linearfactor = Linearfactor;m_invmass = M_linearFactor*m_ Inversemass;}
is to apply the force of the three direction of scaling a certain multiples.
The Applyforce also provides a force to the body,
Voidapplyforce (const btvector3& Force, const btvector3& Rel_pos) {applycentralforce (force);// First, the Force Applytorque (Rel_pos.cross (Force*m_linearfactor)) is applied directly;//Then the torsion force is applied}
The cross-multiplication of the vectors gets another vector perpendicular to the two vectors.
Rel_pos . Cross (Force*m_linearfactor) can get Torsion Force
Suppose force = (0, 0, -10), Rel_pos = (0, 1, 0),
Force * Rel_pos = (-10, 0, 0) to get torsional forces around the x-axis
Remember Applyforce not exerting force alone
Now look at torque.
The previous applyforce has been mentioned, providing a torsion force
Voidapplytorque (const btvector3& torque) {m_totaltorque + = Torque*m_angularfactor;}
Suppose torque = (10, 5,-10)
is to rotate around the torque.normalize axis.
Now to understand Impulse
void Applycentralimpulse (const btvector3& Impulse) {m_linearvelocity + = Impulse *m_linearfactor * M_INVERSEMASS;} void Applytorqueimpulse (const btvector3& torque) {m_angularvelocity + = M_invinertiatensorworld * Torque * m_ Angularfactor;} void Applyimpulse (const btvector3& Impulse, const btvector3& rel_pos) {if (M_inversemass! = btscalar (0.)) {Applycentralimpulse (Impulse), if (m_angularfactor) {Applytorqueimpulse (Rel_pos.cross (Impulse*m_linearfactor));}}}
All the impulse are listed, the introduction of the impulse can be seen in the encyclopedia.
If you want to use it, simply understand the inverse of impulse * quality = increased speed (line speed or angular velocity)
look at the source code will know Applycentralimpulse , Applyimpulse Just follow Applycenterforce and Applyforce almost
If force is to be used to move the body around every frame, the impulse is instantaneous to provide a speed that is only applied when needed
For Set****factor only used when apply***, and set***velocity not used.
void Clearforces ()
The force and torque are removed, but the body is still affected by gravity.
_ballbody->setactivationstate (active_tag);
Of course, when exerting a force, to set the body state to active, only the active object can be simulated, which is also an aspect of optimization.
No source code, no examples, just simple understanding, a lot less, just for learning.
Bullet's understanding of force Torque Impulse