| 17 | } |
| 18 | |
| 19 | RemoteInterpResult RemoteInterp::Step(float deltaT, Vector3Par curPos, Vector3Par curSpeed, const Matrix3& curOrient, |
| 20 | const RemoteInterpParams& p) |
| 21 | { |
| 22 | RemoteInterpResult r; |
| 23 | r.position = curPos; |
| 24 | r.speed = curSpeed; |
| 25 | r.orientation = curOrient; |
| 26 | |
| 27 | if (!_hasTarget || deltaT <= 0) |
| 28 | { |
| 29 | return r; |
| 30 | } |
| 31 | |
| 32 | // Dead-reckon the target forward so the eased entity chases where the server |
| 33 | // unit is now, not where it was when the packet was sent. |
| 34 | _targetPos += _targetSpeed * deltaT; |
| 35 | |
| 36 | Vector3 err = _targetPos - curPos; |
| 37 | float dist = err.Size(); |
| 38 | float objSpeed = curSpeed.Size(); |
| 39 | |
| 40 | float snapDist = p.snapDistAbs + p.snapDistRel * objSpeed; |
| 41 | if (dist > snapDist) |
| 42 | { |
| 43 | // Too far to ease without an obvious rubber-band: cut straight to target. |
| 44 | r.position = _targetPos; |
| 45 | r.speed = _targetSpeed; |
| 46 | r.orientation = _targetOrient; |
| 47 | r.active = true; |
| 48 | r.snapped = true; |
| 49 | _hasTarget = false; |
| 50 | return r; |
| 51 | } |
| 52 | |
| 53 | bool converged = true; |
| 54 | |
| 55 | // Position: step toward the target, capped per frame. |
| 56 | if (dist > p.convergePos) |
| 57 | { |
| 58 | float maxStep = (p.easeSpeedAbs + p.easeSpeedRel * objSpeed) * deltaT; |
| 59 | float move = floatMin(maxStep, dist); |
| 60 | r.position = curPos + err * (move / dist); |
| 61 | r.active = true; |
| 62 | if (move < dist) |
| 63 | { |
| 64 | converged = false; |
| 65 | } |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | r.position = _targetPos; |
| 70 | } |
| 71 | |
| 72 | // Velocity: ease toward the target speed, capped. |
| 73 | Vector3 sDif = _targetSpeed - curSpeed; |
| 74 | float maxSpeedStep = p.maxSpeedChange * deltaT; |
| 75 | if (sDif.SquareSize() > Square(maxSpeedStep)) |
| 76 | { |
no test coverage detected