Ooops
October 28, 2020, 06:21:54 AM

Author Topic: [bb] 3D Doppler Effect by BlitzSupport [ 1+ years ago ]  (Read 1425 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 3D Doppler Effect by BlitzSupport [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : 3D Doppler Effect
Author : BlitzSupport
Posted : 1+ years ago

Description : A re-creation of the classic train-going-by-crossing effect, complete with Doppler (where the pitch rises as the train gets nearer and falls as it goes away).

**** IMPORTANT!!!! ****

You will need this sample, as the demo has been specifically coded with the timing of this sample in mind!

<a href="http://www.railroadxing.com/sounds/amtrak/amtrak 290 train horn for public crossing at grade.wav" target="_blank">http://www.railroadxing.com/sounds/amtrak/amtrak%20290%20train%20horn%20for%20public%20crossing%20at%20grade.wav[/url] (69.4k)

Save the code somewhere, and copy this sample into the same folder.
 


Code :
Code: BlitzBasic
  1. ; -----------------------------------------------------------------------------
  2. ; 3D sound -- Doppler and stereo effects (crank the volume UP!)
  3. ; -----------------------------------------------------------------------------
  4.  
  5. ; -----------------------------------------------------------------------------
  6. ; IMPORTANT: Download this sample BEFORE RUNNING! This code's positioning is
  7. ; hard-coded for this sample!
  8. ; -----------------------------------------------------------------------------
  9. ;
  10. ; http://www.railroadxing.com/sounds/amtrak/amtrak%20290%20train%20horn%20for%20public%20crossing%20at%20grade.wav
  11. ;
  12. ; -----------------------------------------------------------------------------
  13.  
  14. Global gameFPS = 50
  15.  
  16. Graphics3D 640, 480
  17. SetBuffer BackBuffer ()
  18.  
  19. cam = CreateCamera ()
  20. CameraViewport cam, 0, 0, GraphicsWidth (), GraphicsHeight ()
  21.  
  22. ; -----------------------------------------------------------------------------
  23. ; Hack up a really bad train (yes, those carriages ARE meant to be blank!)
  24. ; -----------------------------------------------------------------------------
  25.  
  26. box = CreateCube ()
  27. carriage = CopyEntity (box, box)
  28. carriage2 = CopyEntity (box, box)
  29. carriage3 = CopyEntity (box, box)
  30. carriage4 = CopyEntity (box, box)
  31. ScaleEntity box, 1, 1, 4
  32. PositionEntity carriage, 0, 0, 2.5
  33. PositionEntity carriage2, 0, 0, 5
  34. PositionEntity carriage3, 0, 0, 7.5
  35. PositionEntity carriage4, 0, 0, 10
  36. PositionEntity box, 50, 0, 50
  37. TurnEntity box, 0, -48, 0
  38.  
  39. SetBuffer FrontBuffer ()
  40. doppler = Input ("Enter 0 for normal sound or 1 for 3D Doppler: ")
  41. SetBuffer BackBuffer ()
  42.  
  43. ; -----------------------------------------------------------------------------
  44. ; Sample from 'RailRoadXing.com' -- URL at top of source!
  45. ; -----------------------------------------------------------------------------
  46.  
  47. sample$ = "amtrak%20290%20train%20horn%20for%20public%20crossing%20at%20grade.wav"
  48.  
  49. If doppler
  50.         ; 3D version
  51.         horn = Load3DSound (sample$)
  52.         CreateListener (cam, 0.5, 15, 2)                        ; Listener is attached to camera (trial-and-error parameters ;)
  53.         EmitSound horn, box                                             ; Play the sound from the front of the train
  54. Else
  55.         ; Normal version
  56.         horn = LoadSound (sample$)
  57.         PlaySound horn
  58. EndIf
  59.  
  60. ; Frame-timing stuff...
  61. framePeriod = 1000 / gameFPS
  62. frameTime = MilliSecs () - framePeriod
  63.  
  64. Repeat
  65.  
  66.         ; Frame-timing stuff...
  67.         Repeat
  68.                 frameElapsed = MilliSecs () - frameTime
  69.         Until frameElapsed
  70.         frameTicks = frameElapsed / framePeriod
  71.         frameTween# = Float (frameElapsed Mod framePeriod) / Float (framePeriod)
  72.         For frameLimit = 1 To frameTicks
  73.                 If frameLimit = frameTicks Then CaptureWorld
  74.                 frameTime = frameTime + framePeriod
  75.                 MoveEntity box, 0, 0, -0.5
  76.                 UpdateWorld
  77.         Next
  78.  
  79.         RenderWorld frameTween 
  80.        
  81.         Text 20, 20, "Crap train comin' through!"
  82.         Flip
  83.  
  84. Until EntityZ (box) < -110 Or KeyHit (1)
  85.  
  86. End
  87.  


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal