home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / CH3 / animaudio.cs next >
Encoding:
Text File  |  2006-06-29  |  3.0 KB  |  88 lines

  1. // ========================================================================
  2. //  animaudio.cs
  3. //
  4. //  This module contains the definition of an audio emitter, which uses
  5. //  a synthetic water drop sound. It also contains functions for placing
  6. //  the test emitter in the game world and moving the emitter.
  7. // ========================================================================
  8.  
  9. datablock AudioProfile(TestSound)
  10. // ----------------------------------------------------
  11. //     Definition of the audio profile
  12. // ----------------------------------------------------
  13. {
  14.    filename = "~/data/sound/testing.ogg"; // wave file to use for the sound
  15.    description = "AudioDefaultLooping3d"; // monophonic sound that repeats
  16.        preload = false;  // Engine will only load sound if it encounters it
  17.                           // in the mission
  18. };
  19.  
  20. function InsertTestEmitter()
  21. // ----------------------------------------------------
  22. //     Instantiates the test sound, then inserts it
  23. //     into the game world to the right and offset somewhat
  24. //     from the player's default spawn location.
  25. // ----------------------------------------------------
  26. {
  27.    // An example function which creates a new TestSound object
  28.  %emtr = new AudioEmitter() {
  29.   position = "0 0 0";
  30.   rotation = "1 0 0 0";
  31.   scale = "1 1 1";
  32.   profile = "TestSound"; // Use the profile in the datablock above
  33.   useProfileDescription = "1";
  34.   type = "2";
  35.   volume = "1";
  36.   outsideAmbient = "1";
  37.   referenceDistance = "1";
  38.   maxDistance = "100";
  39.   isLooping = "1";
  40.   is3D = "1";
  41.   loopCount = "-1";
  42.   minLoopGap = "0";
  43.   maxLoopGap = "0";
  44.   coneInsideAngle = "360";
  45.   coneOutsideAngle = "360";
  46.   coneOutsideVolume = "1";
  47.   coneVector = "0 0 1";
  48.   minDistance = "20.0";
  49.  };
  50.  MissionCleanup.add(%emtr);
  51.  
  52.  // Player setup-
  53.  %emtr.setTransform("200 -52 200 0 0 1 0"); // starting location
  54.  echo("Inserting Audio Emitter " @ %emtr);
  55.  return %emtr;
  56. }
  57.  
  58. function AnimSound(%snd, %dist)
  59. // ----------------------------------------------------
  60. //     moves the %snd by %dist amount each time
  61. // ----------------------------------------------------
  62. {
  63.    %xfrm = %snd.getTransform();
  64.    %lx = getword(%xfrm,0); // first, get the current transform values
  65.    %ly = getword(%xfrm,1);
  66.    %lz = getword(%xfrm,2);
  67.    %rx = getword(%xfrm,3);
  68.    %ry = getword(%xfrm,4);
  69.    %rz = getword(%xfrm,5);
  70.    %lx += %dist;           // set the new x position
  71.    %snd.setTransform(%lx SPC %ly SPC %lz 
  72.                SPC %rx SPC %ry SPC %rz SPC %rd);
  73.    schedule(200,0,AnimSound, %snd, %dist);
  74. }
  75.  
  76. function DoAudioMoveTest()
  77. // ----------------------------------------------------
  78. //     a function to tie together the instantiation
  79. //     and the movement in one easy to type function
  80. //     call.
  81. // ----------------------------------------------------
  82. {
  83.    %ms = InsertTestEmitter();
  84.    AnimSound(%ms,1);
  85. }
  86. //DoAudioMoveTest();   // by putting this here, we cause the test to start
  87.                 // as soon as this module has been loaded into memory
  88.