Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. /**
  2. @param info collision info on the object object which is influenced by the deflection (or NULL for landscape collision)
  3. @param normal incident surface normal (normalized)
  4. @param isect intersection point (place where shot entered the object)
  5. @param dist distance traveled inside of the object
  6. @param deltaT time which still needs to be simulated
  7. returns true when the penetration occurred or false if there was no penetration and the impact should be simulated
  8. */
  9. bool ShotShell::SimulatePenetration(const CollisionInfo *info, Vector3Par normal, Vector3Par isect, float dist, float deltaT)
  10. {
  11. const AmmoType *ammoType = Type();
  12. float penetrability = info->BulletPenetrability();
  13. if ((penetrability <= 0.0f) || (ammoType->explosive >= 0.7f && info->BulletPenetrability() > 100))
  14. return false;
  15. // check distance traveled in the object, assume bullet deceleration is linear
  16. float distInside = info->DistInside();
  17. Assert(distInside > 0.0f);
  18.  
  19. if(info->Thickness()>0)
  20. { //use thickness only when bullet enters object
  21. if(info->entry)
  22. {//bigger the entry angle is, more material we go trough
  23. float cosAngle = info->dirOutNotNorm.Normalized().DotProduct(FutureVisualState()._speed.Normalized());
  24. float thick = (cosAngle != 0)? (fabsf(info->Thickness() / cosAngle)) : distInside;
  25. //collision geometry is not thick enough
  26. distInside = (info->exit)? distInside = floatMin(thick,distInside) : thick;
  27. }
  28. //thickness has already been used
  29. else penetrability = 0.01f;
  30. }
  31.  
  32. float speed = FutureVisualState()._speed.Size();
  33. float deceleration = distInside * penetrability / ammoType->caliber;
  34. if (speed <= deceleration)
  35. return false;
  36. Vector3 lDirNorm = FutureVisualState()._speed.Normalized();
  37. // move the bullet to the point where it goes out of the object
  38. Vector3 newPos = isect + distInside * lDirNorm;
  39. // reduce speed, change direction, continue traveling
  40. float reduceSpeed = deceleration / speed;
  41. const float changeSize = 0.25f;
  42. Vector3 changeDir = Vector3(GRandGen.Gauss(-changeSize, 0.0f, changeSize) * reduceSpeed,
  43. GRandGen.Gauss(-changeSize, 0.0f, changeSize) * reduceSpeed,
  44. GRandGen.Gauss(-changeSize, 0.0f, changeSize) * reduceSpeed);
  45. Vector3 dir = lDirNorm + changeDir;
  46. dir.Normalize();
  47. Vector3 newSpeed = dir * (speed - deceleration);
  48. // FIXME RHAL: use _speed or newSpeed here?
  49. float timeInside = distInside * FutureVisualState()._speed.InvSize();
  50. // if we did not simulate any time, we have a problem - what can we do? Next iteration will detect collision again
  51. Assert(timeInside > 0.0f);
  52. // FIXME RHAL: resolve this case properly
  53. Assert(timeInside <= deltaT*1.05f);
  54. if (timeInside > deltaT)
  55. timeInside = deltaT;
  56. // handle the in-side object part
  57. UpdatePosAndSpeed("penetrating", timeInside, newPos, penetrability);
  58. // revert time back to the moment we went out
  59. deltaT -= timeInside;
  60. DebugShotShell(info, timeInside, FutureVisualState()._speed, newSpeed, "P");
  61. SimulateHit(info, isect, normal, newSpeed);
  62. FutureVisualState()._speed = newSpeed;
  63. if (dist > 0.01f)
  64. // make sure the partial segment is rendered; after penetration we want no more suppression tracing, the trajectory is unpredictable
  65. TerminateSegment(true);
  66. SimulateMovement(deltaT, true);
  67.  
  68. return true;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement