1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/**************************************************************************\
*
* This file is part of the Coin 3D visualization library.
* Copyright (C) by Kongsberg Oil & Gas Technologies.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.GPL at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using Coin with software that can not be combined with the GNU
* GPL, and for taking advantage of the additional benefits of our
* support services, please contact Kongsberg Oil & Gas Technologies
* about acquiring a Coin Professional Edition License.
*
* See http://www.coin3d.org/ for more information.
*
* Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
* http://www.sim.no/ sales@sim.no coin-support@coin3d.org
*
\**************************************************************************/
/*!
\class SoListener SoListener.h Inventor/nodes/SoListener.h
\brief The SoListener class defines listener attributes used when rendering sound.
\ingroup nodes
\ingroup sound
When rendering geometry, one needs to have a camera defining certain
attributes related to vieweing. The SoListener plays a similar
role when it comes to rendering audio.
If no SoListener has been encountered when a SoVRMLSound node
renders itself, it will use the position and the orientation of the
current camera. In this case, a gain of 1, a dopplerVelocity of 0
and a dopplerFactor of 0 will be assumed.
Coin does not currently support doppler effects, so the
dopplerVelocity and dopplerFactor fields are currently ignored.
<b>FILE FORMAT/DEFAULTS:</b>
\code
Listener {
position 0 0 0
orientation 0 0 1 0
dopplerVelocity 0 0 0
dopplerFactor 0
gain 1
}
\endcode
\sa SoVRMLSound
*/
#include <Inventor/nodes/SoListener.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
#include <Inventor/actions/SoAudioRenderAction.h>
#include <Inventor/elements/SoModelMatrixElement.h>
#include <Inventor/errors/SoDebugError.h>
#include <Inventor/misc/SoAudioDevice.h>
#include <Inventor/elements/SoListenerPositionElement.h>
#include <Inventor/elements/SoListenerOrientationElement.h>
#include <Inventor/elements/SoListenerDopplerElement.h>
#include <Inventor/elements/SoListenerGainElement.h>
#include "nodes/SoSubNodeP.h"
/*!
\var SoSFVec3f SoListener::position
Listener position. Defaults to (0.0f, 0.0f, 0.0f).
*/
/*!
\var SoSFVec3f SoListener::orientation
Listener orientation specified as a rotation value from the default
orientation where the listener is looking pointing along the
negative z-axis, with "up" along the positive y-axis. Defaults to
SbRotation(SbVec3f(0.0f, 0.0f, 1.0f), 0.0f).
*/
/*!
\var SoSFVec3f SoListener::gain
The gain is a scalar amplitude multiplier that attenuates all sounds
in the scene. The legal range is [0.0f, any), however a gain value >
1.0f might be clamped to 1.0f by the audio device. Defaults to 1.0f,
meaning that the sound is un-attenuated. A gain value of 0.5f would
be equivalent to a 6dB attenuation. If gain is set to 0.0f, no sound
can be heard.
*/
/*!
\var SoSFVec3f SoListener::dopplerVelocity
The doppler velocity of the sound. It is the application
programmer's responsibility to set this value. Coin does not update
this value automatically based on changes in a sound's
position. The default value is (0.0f, 0.0f, 0.0f).
Coin does not yet support doppler effects.
*/
/*!
\var SoSFFloat SoListener::dopplerFactor
The amount of doppler effect applied to the sound. The legal range
is [0.0f, any>, where 0.0f is default and disable all doppler
effects, 1.0f would be a typical value for this field if doppler
effects are required.
Coin does not yet support doppler effects.
*/
SO_NODE_SOURCE(SoListener);
// Doc in superclass.
void SoListener::initClass()
{
SO_NODE_INTERNAL_INIT_CLASS(SoListener, SO_FROM_COIN_2_0);
SO_ENABLE(SoAudioRenderAction, SoListenerPositionElement);
SO_ENABLE(SoAudioRenderAction, SoListenerOrientationElement);
SO_ENABLE(SoAudioRenderAction, SoListenerDopplerElement);
SO_ENABLE(SoAudioRenderAction, SoListenerGainElement);
}
/*!
Contructor.
*/
SoListener::SoListener()
{
SO_NODE_INTERNAL_CONSTRUCTOR(SoListener);
SO_NODE_ADD_FIELD(position, (0.0f, 0.0f, 0.0f));
SO_NODE_ADD_FIELD(orientation,
(SbRotation(SbVec3f(0.0f, 0.0f, 1.0f), 0.0f)));
SO_NODE_ADD_FIELD(dopplerVelocity, (0.0f, 0.0f, 0.0f));
SO_NODE_ADD_FIELD(dopplerFactor, (0.0f));
SO_NODE_ADD_FIELD(gain, (1.0f));
}
/*!
Destructor.
*/
SoListener::~SoListener()
{
}
// Doc in superclass
void
SoListener::audioRender(SoAudioRenderAction *action)
{
SoState * state = action->getState();
if (! this->position.isIgnored()) {
SbVec3f pos, worldpos;
pos = this->position.getValue();
SoModelMatrixElement::get(state).multVecMatrix(pos, worldpos);
SoListenerPositionElement::set(state, this, worldpos, TRUE);
#if COIN_DEBUG && 0
float x, y, z;
worldpos.getValue(x, y, z);
SoDebugError::postInfo("SoListener::audioRender", "listenerpos "
"(%0.2f, %0.2f, %0.2f)", x, y, z);
#endif // debug
}
if (! this->orientation.isIgnored()) {
SbVec3f t;
SbRotation r;
SbVec3f s;
SbRotation so;
SoModelMatrixElement::get(state).getTransform(t, r, s, so);
r *= this->orientation.getValue();
SoListenerOrientationElement::set(state, this, r, TRUE);
}
if (! this->dopplerVelocity.isIgnored())
SoListenerDopplerElement::setDopplerVelocity(state, this,
this->dopplerVelocity.getValue());
if (! this->dopplerFactor.isIgnored())
SoListenerDopplerElement::setDopplerFactor(state, this,
this->dopplerFactor.getValue());
if (! this->gain.isIgnored())
SoListenerGainElement::set(state, this, this->gain.getValue());
}
|