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

Method ApplyForcesAndFriction

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

Source from the content-addressed store, hash-verified

671#endif
672
673void Entity::ApplyForcesAndFriction(float deltaT, Vector3Par force, Vector3Par torque, const FrictionPoint* fric,
674 int nFric)
675{
676 float frictionCoef = 10;
677 float angularFrictionCoef = 1.0f;
678
679 Vector3 wAccel = force * GetInvMass();
680 Vector3 oldSpeed = _speed;
681
682 _angMomentum += torque * deltaT;
683 _speed += wAccel * deltaT;
684
685 float rigid = Rigid();
686
687 _speed += _impulseForce * (GetInvMass() * rigid);
688 _angMomentum += _impulseTorque * rigid;
689
690 _impulseTorque = VZero;
691 _impulseForce = VZero;
692
693 Matrix3Val orientation0 = Transform().Orientation();
694 Matrix3Val invOrientation0 = InvTransform().Orientation();
695 if (_shape)
696 {
697 _invAngInertia = orientation0 * InvInertia() * invOrientation0;
698 }
699 else
700 {
701 _invAngInertia = M3Zero;
702 }
703
704 _angVelocity = _invAngInertia * _angMomentum;
705
706#if 1
707 if (nFric > 0)
708 {
709 AUTO_STATIC_ARRAY(Vector3, pVelChange, 128);
710 pVelChange.Resize(nFric);
711
712 Vector3 velChange(VZero);
713 Vector3 angMomChange(VZero);
714 float mass = GetMass();
715
716 Vector3 wCenter(VFastTransform, ModelToWorld(), GetCenterOfMass());
717 float sumFricCoef = 0;
718 for (int f = 0; f < nFric; f++)
719 {
720 const FrictionPoint& fp = fric[f];
721 sumFricCoef += fp.frictionCoef;
722 }
723 // sum may exceed 1 when in water; keep combined force in range
724 float invSumFricCoef = sumFricCoef > 1 ? 1.0f / sumFricCoef : 1;
725
726 float angMomFriction = 0;
727 for (int f = 0; f < nFric; f++)
728 {
729 const FrictionPoint& fp = fric[f];
730 Vector3 pCenter = fp.pos - wCenter;

Callers

nothing calls this directly

Calls 15

TransformFunction · 0.85
InvInertiaFunction · 0.85
GetCenterOfMassFunction · 0.85
ColorClass · 0.85
saturateMinFunction · 0.85
SaturateAbsFunction · 0.85
floatMinFunction · 0.85
GlobalShowMessageFunction · 0.85
AUTO_STATIC_ARRAYFunction · 0.70
GetInvMassFunction · 0.50
RigidFunction · 0.50
GetMassFunction · 0.50

Tested by

no test coverage detected