Introduction to Force Torque Impulse and bullettorque
Before learning about Force Impulse Torque, let's take a look at setLinearVelocity and setAngularVelocity.
One is the wire speed and the other is the angular velocity.
It is easy to understand to set the line speed and velocity of the body.
// Line speed const btVector3 & direction () constvoid forward (const btVector3 & lin_vel) // angular speed const btVector3 & direction () constvoid forward (const btVector3 & ang_vel)
Learn more about 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;}
Add force * m_linearFactor based on the original force of the body.
void setLinearFactor(const btVector3& linearFactor){m_linearFactor = linearFactor;m_invMass = m_linearFactor*m_inverseMass;}
It is a factor that scales each of the three directions of the applied force.
ApplyForce also provides a force to the body,
VoidapplyForce (const btVector3 & force, const btVector3 & rel_pos) {applyCentralForce (force); // apply the force upon applyTorque (rel_pos.cross (force * m_linearFactor) First )); // then exert torsion}
Returns another vector perpendicular to the two vectors.
Rel_pos.cross (force * m_linearFactor) returns torsion.
Assume that force = (0, 0,-10), rel_pos = (0, 1, 0 ),
Force * rel_pos = (-10, 0, 0) to obtain the torsion Force around the X axis.
Remember, applyForce does not apply additional force alone.
Now let's look at Torque.
As mentioned above, applyForce provides a torsion force.
voidapplyTorque(const btVector3& torque){m_totalTorque += torque*m_angularFactor;}
Suppose torque = (10, 5,-10)
It is to rotate around torque. normalize.
Learn more about 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));}}}
List all Impulse entries. For more information about Impulse, see the encyclopedia.
To use it, simply understand the reciprocal of impulse * Quality = increase speed (line speed or angular velocity)
The applyCentralImpulse and applyImpulse are similar to applyCenterForce and applyForce.
If Force is used to move the body, the Force is applied to each frame. Impulse provides a speed in an instant and is only applied when necessary.
Set *** Factor is only used when apply ***, but set *** Velocity is not used.
Void clearForces ()
Clears the applied Force and Torque, but the body is still affected by the gravity.
_ BallBody-> setActivationState (ACTIVE_TAG );
Of course, when a force is applied, the body state must be set to activity. Only the activity object can be simulated, which is also an aspect of optimization.
No source code, no examples, just a simple understanding, not many, just for learning.