MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ApplyForces

Method ApplyForces

engine/Poseidon/World/Simulation/Simul.cpp:592–635  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592void Entity::ApplyForces(float deltaT, Vector3Par force, Vector3Par torque, Vector3Par friction,
593 Vector3Par torqueFriction, float staticFric)
594{
595 Vector3 accel = DirectionWorldToModel(force * GetInvMass());
596 Vector3 fricAccel = DirectionWorldToModel(friction * GetInvMass());
597 Vector3 oldSpeed = _speed;
598 Vector3 speed(VMultiply, DirWorldToModel(), _speed);
599 Friction(speed, fricAccel, accel, deltaT);
600 DirectionModelToWorld(_speed, speed);
601 if (deltaT > 0)
602 {
603 _acceleration = (_speed - oldSpeed) * (1 / deltaT);
604 }
605 else
606 {
607 _acceleration = VZero;
608 }
609 Friction(_angMomentum, torqueFriction, torque, deltaT);
610
611 float rigid = Rigid();
612 _speed += _impulseForce * (GetInvMass() * rigid);
613 _angMomentum += _impulseTorque * rigid;
614
615 float staticCanHold = staticFric * GetInvMass() * deltaT;
616 if (_speed.SquareSize() < Square(staticCanHold))
617 {
618 _speed = VZero;
619 }
620 _impulseTorque = VZero;
621 _impulseForce = VZero;
622
623 Matrix3Val orientation0 = Transform().Orientation();
624 Matrix3Val invOrientation0 = InvTransform().Orientation();
625 if (_shape)
626 {
627 _invAngInertia = orientation0 * InvInertia() * invOrientation0;
628 }
629 else
630 {
631 _invAngInertia = M3Zero;
632 }
633
634 _angVelocity = _invAngInertia * _angMomentum;
635}
636
637inline float fFric(float x)
638{

Callers

nothing calls this directly

Calls 7

FrictionFunction · 0.85
TransformFunction · 0.85
InvInertiaFunction · 0.85
GetInvMassFunction · 0.50
RigidFunction · 0.50
SquareFunction · 0.50
SquareSizeMethod · 0.45

Tested by

no test coverage detected