| 671 | #endif |
| 672 | |
| 673 | void 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; |
nothing calls this directly
no test coverage detected