root/juggler/tags/1.0.5/Sound/vjSound.cpp
| Revision 2828, 2.3 kB (checked in by patrickh, 8 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998, 1999, 2000 by Iowa State University |
| 4 | * |
| 5 | * Original Authors: |
| 6 | * Allen Bierbaum, Christopher Just, |
| 7 | * Patrick Hartling, Kevin Meinert, |
| 8 | * Carolina Cruz-Neira, Albert Baker |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public |
| 21 | * License along with this library; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | * ----------------------------------------------------------------- |
| 26 | * File: $RCSfile$ |
| 27 | * Date modified: $Date$ |
| 28 | * Version: $Revision$ |
| 29 | * ----------------------------------------------------------------- |
| 30 | * |
| 31 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 32 | |
| 33 | #include <Sound/vjSoundEngine.h> |
| 34 | #include <Sound/vjSound.h> |
| 35 | |
| 36 | // calculate the sound volume based on the observer position, sound position, falloff, and volume |
| 37 | void vjSound::getPercievedVolume( float& volume ) const |
| 38 | { |
| 39 | // get the observer's position |
| 40 | vjVec3 observerPos; |
| 41 | this->engine().getPosition( observerPos[0], observerPos[1], observerPos[2] ); |
| 42 | |
| 43 | // what is the sound's position |
| 44 | vjVec3 soundPos; |
| 45 | this->getPosition( soundPos[0], soundPos[1], soundPos[2] ); |
| 46 | |
| 47 | // how far away is the sound from the observer. |
| 48 | vjVec3 displacement = observerPos - soundPos; |
| 49 | float length = displacement.length(); |
| 50 | |
| 51 | // set the sound's volume |
| 52 | this->getVolume( volume ); |
| 53 | |
| 54 | // calculate the percieved volume |
| 55 | if (length > mFalloff) |
| 56 | { |
| 57 | volume = 0; |
| 58 | } |
| 59 | |
| 60 | else //if (length <= mFalloff) |
| 61 | { |
| 62 | // position=0 is full volume |
| 63 | // posiiton=falloff is no volume |
| 64 | |
| 65 | float amount = 1.0f - (length / mFalloff); |
| 66 | volume *= amount; |
| 67 | } |
| 68 | } |
Note: See TracBrowser for help on using the browser.
