Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

pfSoundNode.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2003 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile: pfSoundNode.cpp,v $
00027  * Date modified: $Date: 2003/06/13 23:34:31 $
00028  * Version:       $Revision: 1.16 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <snx/sonix.h>
00034 
00035 #include <vrj/vrjConfig.h>
00036 #include <vrj/Sound/pf/pfSoundNode.h>
00037 
00038 
00039 pfSoundNode::pfSoundNode( const std::string& sound, bool isPositional ) : mIsPositional( true )
00040 {
00041    this->setPositional( isPositional );
00042    this->setSound( sound );
00043    this->setType(classType);  // Set the type
00044 }
00045 
00046 
00047 // app() - APP traversal function.  This overloads the standard pfDCS
00048 // app() method, which will be called each frame during the APP
00049 // traversal of the scene graph (*only if* needsApp() (below) returns
00050 // TRUE).
00051 // app() is called automatically by Performer; it is not called directly
00052 // by a program.
00053 int pfSoundNode::app(pfTraverser *trav)
00054 {
00055    // update the sound attributes (position) based on the current
00056    // position of this node.
00057    // only do it if the sound is a positional sound.
00058    if (mSound != "" && mIsPositional == true)
00059    {
00060       // get position of this sound in relation to the user's orientation and position
00061       // NOTE: the sound will change position if the user rotates without translation.
00062       //       it should orbit the user, so that the audio will pan correctly.
00063       pfMatrix matrix, traverserMatrix, dcsMatrix;
00064       matrix.makeIdent();
00065 
00066       //: take the sound from soundspace to userspace.
00067 
00068       // add in any offset due to this DCS node
00069       // (since the traverser hasn't yet added it to it's matrix stack.)
00070       // *NOTE: this is the matrix that takes the sound from local(sound)space to modelspace.
00071       this->getMat( dcsMatrix ); //TODO: don't call this.
00072       // ...to get the location of the sound in modelspace, you'd do an invertFull here, but we want it in user space..
00073       matrix.postMult( dcsMatrix );
00074 
00075       // add in any offset due to navigation and any other DCS xforms currently on the traverser's stack.
00076       // this is the position of the model's origin in relation to a user at position 0,0,0
00077       // this is just the nav matrix, which should be on the matrix stack right now...
00078       // *NOTE: this is the matrix that takes the sound from modelspace to userspace
00079       trav->getMat( traverserMatrix );
00080       // ...to get the location of the sound in modelspace, you'd do an invertFull here, but we want it in user space..
00081       matrix.postMult( traverserMatrix );
00082 
00083       pfCoord coord;
00084       matrix.getOrthoCoord( &coord );
00085 
00086       // set my sound's position.
00087       pfVec3 pf_soundPosition = coord.xyz;
00088       gmtl::Vec3f soundPosition = vrj::GetVjVec( pf_soundPosition );
00089       sonix::instance()->setPosition( mSound, soundPosition[0], soundPosition[1], soundPosition[2] );
00090 
00091       // Engine's update should be called by the app's frame process,
00092       // or in juggler's manager (not both, of course)...
00093 
00094       // use this for debugging the location of the sound reletive to the user.
00095       //std::cout<<"["<<mSound->getName()<<"] sound in userspace: "<<soundPosition[0]<<" "<<soundPosition[1]<<" "<<soundPosition[2]<<"\n"<<std::flush;
00096    }
00097    else
00098    {
00099       // redundant (fixme), but make sure it's 0.0f,0.0f,0.0f
00100       // this makes the sound the same as the observer.
00101       sonix::instance()->setPosition( mSound, 0.0f, 0.0f, 0.0f );
00102    }
00103 
00104    return pfDCS::app( trav );  // call the parent class's app()
00105 
00106 }
00107 
00108 //---------------------------------------------------------------------//
00109 // Performer type data - this part is required for any class which
00110 // is derived from a Performer class.  It creates a new pfType
00111 // which identifies objects of this class.  All constructors for
00112 // this class must then call setType(classType_).
00113 pfType* pfSoundNode::classType = NULL;
00114 
00115 void pfSoundNode::init()
00116 {
00117    vprDEBUG(vprDBG_ALL, vprDBG_CONFIG_LVL)
00118       << "[pfSoundNode] Registering sound node with performer.\n"
00119       << vprDEBUG_FLUSH;
00120 
00121    if (classType == NULL)
00122    {
00123         pfDCS::init();           // Initialize my parent
00124         classType =  new pfType(pfDCS::getClassType(), "pfSoundNode");  // Create the new type
00125    }
00126 }
00127 //----------------------------------------------------------------------//

Generated on Sun May 2 15:10:17 2004 for VR Juggler by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002