Guest User

Untitled

a guest
Jul 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. /*
  2. ==============
  3. BG_SplatterPattern
  4.  
  5. For the shotgun, frag nade, acidtubes, flamer, etc...
  6. ==============
  7. */
  8. void BG_SplatterPattern( vec3_t origin2, int seed, int passEntNum,
  9. splatterData_t *data, void (*func)( splatterData_t *data ),
  10. void (*trace)( trace_t *, const vec3_t,
  11. const vec3_t, const vec3_t,
  12. const vec3_t, int, int ) ) {
  13. int i;
  14. const int modeIndex = data->weaponMode - 1;
  15. weapon_t weapon = data->weapon;
  16. const int splatterNumber = BG_Weapon( weapon )->splatter[modeIndex].number;
  17. const float spread = BG_Weapon( weapon )->splatter[modeIndex].spread;
  18. const float range = BG_Weapon( weapon )->splatter[modeIndex].range;
  19. vec3_t origin, forward, rotationDir, dir, end;
  20. const vec3_t upAbsolute = { 0.0f, 0.0f, 1.0f };
  21. float rotationAngle, rotationDirLength, dot;
  22. trace_t tr;
  23.  
  24. Com_Assert( modeIndex >= 0 &&
  25. modeIndex < 3 &&
  26. "BG_SplatterPattern: invalid weaponMode" );
  27. Com_Assert( trace &&
  28. "BG_SplatterPattern: trace is NULL" );
  29. Com_Assert( func &&
  30. "BG_Weapon( weapon )->splatter[modeIndex].spread: func is NULL" );
  31. Com_Assert( spread >= 0 &&
  32. spread <= 180 &&
  33. "BG_SplatterPattern: spread is out of range" );
  34.  
  35. VectorCopy( data->origin, origin );
  36.  
  37. VectorCopy( origin2, forward );
  38. CrossProduct( forward, upAbsolute, rotationDir );
  39. rotationDirLength = VectorLength( rotationDir );
  40. dot = DotProduct( upAbsolute, forward );
  41.  
  42. if( rotationDirLength > 0 ) {
  43. VectorNormalize( rotationDir );
  44. rotationAngle = RAD2DEG( acos( dot ) );
  45. } else if( dot > 0.0f ) {
  46. rotationAngle = 0;
  47. } else {
  48. rotationAngle = 180;
  49. }
  50.  
  51.  
  52. // generate the "random" spread pattern
  53. for( i = 0; i < splatterNumber; i++ ) {
  54. vec3_t splatterAngles,temp;
  55.  
  56. //find the splatter angles
  57. splatterAngles[PITCH] = Q_random( &seed ) * spread;
  58. AngleNormalize180( splatterAngles[PITCH] );
  59. splatterAngles[YAW] = Q_random( &seed ) * 360;
  60. AngleNormalize360( splatterAngles[YAW] );
  61. splatterAngles[ROLL] = 0;
  62.  
  63. //get the new dir vector
  64. AngleVectors( splatterAngles, temp, NULL, NULL );
  65. VectorNormalize( temp );
  66.  
  67. if( rotationDirLength > 0 ) {
  68. RotatePointAroundVector( dir, rotationDir, temp, rotationAngle );
  69. } else if( dot > 0.0f ){
  70. VectorCopy( temp, dir );
  71. } else {
  72. VectorScale( temp, -1.0f, dir );
  73. }
  74.  
  75. VectorMA( origin, range, dir, end );
  76.  
  77. trace( &tr, origin, NULL, NULL, end, passEntNum, MASK_SHOT );
  78. data->tr = &tr;
  79. func( data );
  80. }
  81. }
Add Comment
Please, Sign In to add comment