BVB Source Codes

CRYENGINE Show VehicleNoiseGenerator.h Source code

Return Download CRYENGINE: download VehicleNoiseGenerator.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef _VEH_NOISE_GEN__H__
  4. #define _VEH_NOISE_GEN__H__
  5.  
  6. class CVehicleNoiseValue
  7. {
  8. public:
  9.         CVehicleNoiseValue();
  10.         void  SetAmpFreq(float amplitude, float frequency);
  11.         void  Setup(float amplitude, float frequency, int32 offset = 0);
  12.         float Update(float dt);
  13.  
  14. private:
  15.         float PseudoNoise(int x);
  16.         float Interp(float a, float b, float t);
  17.         float SoftNoise(int32 x);
  18.  
  19. private:
  20.         float m_amplitude;
  21.         float m_frequency;
  22.         int32 m_position;
  23.         int32 m_offset;
  24. };
  25.  
  26. class CVehicleNoiseValue3D
  27. {
  28. public:
  29.         CVehicleNoiseValue x;
  30.         CVehicleNoiseValue y;
  31.         CVehicleNoiseValue z;
  32.  
  33.         Vec3 Update(float tickTime)
  34.         {
  35.                 return Vec3(x.Update(tickTime), y.Update(tickTime), z.Update(tickTime));
  36.         }
  37. };
  38.  
  39. ////////////////////////////////////////////////////////////////////////////////////////////////////
  40. // CVehicleNoiseValue
  41. ////////////////////////////////////////////////////////////////////////////////////////////////////
  42.  
  43. NO_INLINE_WEAK CVehicleNoiseValue::CVehicleNoiseValue()
  44. {
  45.         m_offset = 0;
  46.         m_position = 0;
  47.         m_amplitude = 0.f;
  48.         m_frequency = 0.f;
  49. }
  50.  
  51. NO_INLINE_WEAK float CVehicleNoiseValue::PseudoNoise(int32 x)
  52. {
  53.         // Predictable random number generator for input 'x' (output is -1 to +1)
  54.         x = (x << 13) ^ x;
  55.         x = x * (x * x * 19379 + 819233) + 1266122899;
  56.         return ((x & 0x7fffffff) * (1.f / 1073741823.5f)) - 1.f;
  57. }
  58.  
  59. NO_INLINE_WEAK float CVehicleNoiseValue::Interp(float a, float b, float t)
  60. {
  61.         // Interpolate between a and b where t is the amount (0 to 1)
  62.         t = (1.f - cosf(t * 3.14159265358979323f)) * 0.5f; // Change t to a curve
  63.         return a * (1.f - t) + b * t;
  64. }
  65.  
  66. NO_INLINE_WEAK float CVehicleNoiseValue::SoftNoise(int32 x)
  67. {
  68.         // Soft Perlin noise
  69.         float a = PseudoNoise(x >> 16);
  70.         float b = PseudoNoise((x >> 16) + 1);
  71.         return Interp(a, b, (x & 0xffff) / 65536.f);
  72. }
  73.  
  74. NO_INLINE_WEAK void CVehicleNoiseValue::SetAmpFreq(float amplitude, float frequency)
  75. {
  76.         m_amplitude = amplitude;
  77.         m_frequency = frequency;
  78. }
  79.  
  80. NO_INLINE_WEAK void CVehicleNoiseValue::Setup(float amplitude, float frequency, int32 offset)
  81. {
  82.         SetAmpFreq(amplitude, frequency);
  83.         m_offset = offset;
  84.         m_position = 0;
  85. }
  86.  
  87. NO_INLINE_WEAK float CVehicleNoiseValue::Update(float tickTime)
  88. {
  89.         float r = SoftNoise(m_position + m_offset) * m_amplitude;
  90.         m_position += (int32)(tickTime * 65536.f * m_frequency);
  91.         return r;
  92. }
  93.  
  94. #endif
  95.  
downloadVehicleNoiseGenerator.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top