Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Audio::Listener Class Reference

#include <Listener.h>

Classes

struct  Dirty
 

Public Member Functions

 Listener () throw ()
 
virtual ~Listener ()
 
LVector3 getPosition () const throw ()
 
void setPosition (LVector3 x) throw ()
 
Vector3 getAtDirection () const throw ()
 
Vector3 getUpDirection () const throw ()
 
void setOrientation (Vector3 at, Vector3 up) throw ()
 
Vector3 getVelocity () const throw ()
 
void setVelocity (Vector3 x) throw ()
 
Range< ScalargetAngleRange () const throw ()
 
void setAngleRange (Range< Scalar > r) throw ()
 
Range< ScalargetCosAngleRange () const throw ()
 
void setCosAngleRange (Range< Scalar > r) throw ()
 
Scalar getRadius () const throw ()
 
void setRadius (Scalar r) throw ()
 
Scalar getGain () const throw ()
 
void setGain (Scalar g) throw ()
 
SharedPtr< RenderableListenergetRenderable () const throw ()
 
void setRenderable (SharedPtr< RenderableListener > ptr) throw ()
 
SharedPtr< UserDatagetUserData () const throw ()
 
void setUserData (SharedPtr< UserData > ptr) throw ()
 
void update (int flags) throw ()
 
Vector3 toLocalDirection (Vector3 dir) const throw ()
 

Protected Attributes

struct Audio::Listener::Dirty dirty
 

Detailed Description

Listener class

Remarks
This class represents a scene listener. Its interface is quite simple. It's possible that scene managers (scenes) will provide their own implementation.
This class is not abstract, its interface is simple enough so that Listener
acts both as interface and basic implementation.

Definition at line 21 of file Listener.h.

Constructor & Destructor Documentation

Listener::Listener ( )
throw (
)

Construct a default listener with default parameters

Definition at line 12 of file Listener.cpp.

12  :
13  cosAngleRange(-1,-1),
14  position(0,0,0),
15  atDirection(0,0,-1),
16  upDirection(0,1,0),
17  velocity(0,0,0),
18  radius(1),
19  gain(1),
20  worldToLocal(1) // set to identity, given default settings
21  {
22  }
Listener::~Listener ( )
virtual

Definition at line 24 of file Listener.cpp.

25  {
26  }

Member Function Documentation

Range< Scalar > Listener::getAngleRange ( ) const
throw (
)

Return the listener's minimum/maximum perception angle

Remarks
A listener's sound perception may be directional or omnidirectional. Perception will be full within minimum directional drift. Further drift will attenuate the sound until it reaches maximum attenuation by the maximum perception angle. Notice that maximum attenuation may not be full silence.

Definition at line 28 of file Listener.cpp.

References UniverseUtil::acos(), Audio::Range< T >::max, and Audio::Range< T >::min.

29  {
30  return Range<Scalar>(Scalar(acos(cosAngleRange.min)),
31  Scalar(acos(cosAngleRange.max)));
32  }
Vector3 Audio::Listener::getAtDirection ( ) const
throw (
)
inline

Return the listener's front direction

Definition at line 89 of file Listener.h.

89 { return atDirection; }
Range<Scalar> Audio::Listener::getCosAngleRange ( ) const
throw (
)
inline
See Also
getAngleRange
Remarks
This version returns cosine-angles rather than radians, much quicker

Definition at line 116 of file Listener.h.

116 { return cosAngleRange; }
Scalar Audio::Listener::getGain ( ) const
throw (
)
inline

Get the listener's gain

Definition at line 129 of file Listener.h.

129 { return gain; }
LVector3 Audio::Listener::getPosition ( ) const
throw (
)
inline

Return the listener's central position in 3D space

Definition at line 83 of file Listener.h.

Referenced by Audio::SceneManager::activationPhaseImpl().

83 { return position; }
Scalar Audio::Listener::getRadius ( ) const
throw (
)
inline

Get the listener's radius

Definition at line 122 of file Listener.h.

122 { return radius; }
SharedPtr<RenderableListener> Audio::Listener::getRenderable ( ) const
throw (
)
inline

Get renderer-specific data associated (and destroyed) with this sound source

Definition at line 136 of file Listener.h.

136 { return rendererDataPtr; }
Vector3 Audio::Listener::getUpDirection ( ) const
throw (
)
inline

Return the listener's up direction

Definition at line 92 of file Listener.h.

92 { return upDirection; }
SharedPtr<UserData> Audio::Listener::getUserData ( ) const
throw (
)
inline

Get user-specific data associated (and destroyed) with this listener

Definition at line 142 of file Listener.h.

142 { return userDataPtr; }
Vector3 Audio::Listener::getVelocity ( ) const
throw (
)
inline

Return the listener's velocity

Definition at line 98 of file Listener.h.

98 { return velocity; }
void Listener::setAngleRange ( Range< Scalar r)
throw (
)
See Also
getAngleRange

Definition at line 34 of file Listener.cpp.

References UniverseUtil::cos().

35  {
36  cosAngleRange.min = Scalar(cos(r.min));
37  cosAngleRange.max = Scalar(cos(r.max));
38  dirty.attributes = 1;
39  }
void Audio::Listener::setCosAngleRange ( Range< Scalar r)
throw (
)
inline
See Also
getAngleRange
Remarks
This version takes cosine-angles rather than radians, much quicker

Definition at line 119 of file Listener.h.

References Audio::Listener::Dirty::attributes, and dirty.

119 { cosAngleRange = r; dirty.attributes = 1; }
void Audio::Listener::setGain ( Scalar  g)
throw (
)
inline

Set the listener's gain

Definition at line 132 of file Listener.h.

References dirty, g, and Audio::Listener::Dirty::gain.

132 { gain = g; dirty.gain = 1; }
void Audio::Listener::setOrientation ( Vector3  at,
Vector3  up 
)
throw (
)
inline

Set the listener's orientation

Definition at line 95 of file Listener.h.

References dirty, Audio::Listener::Dirty::location, and up.

95 { atDirection = at; upDirection = up; dirty.location = 1; }
void Audio::Listener::setPosition ( LVector3  x)
throw (
)
inline

Set the listener's central position in 3D space

Definition at line 86 of file Listener.h.

References dirty, Audio::Listener::Dirty::location, and x.

86 { position = x; dirty.location = 1; }
void Audio::Listener::setRadius ( Scalar  r)
throw (
)
inline

Set the listener's radius

Definition at line 125 of file Listener.h.

References Audio::Listener::Dirty::attributes, and dirty.

125 { radius = r; dirty.attributes = 1; }
void Audio::Listener::setRenderable ( SharedPtr< RenderableListener ptr)
throw (
)
inline

Set renderer-specific data to be associated (and destroyed) with this sound source

Definition at line 139 of file Listener.h.

References dirty, and Audio::Listener::Dirty::setAll().

139 { rendererDataPtr = ptr; dirty.setAll(); }
void Audio::Listener::setUserData ( SharedPtr< UserData ptr)
throw (
)
inline

Set user-specific data to be associated (and destroyed) with this listener

Definition at line 145 of file Listener.h.

145 { userDataPtr = ptr; }
void Audio::Listener::setVelocity ( Vector3  x)
throw (
)
inline

Set the listener's velocity

Definition at line 101 of file Listener.h.

References dirty, Audio::Listener::Dirty::location, and x.

101 { velocity = x; dirty.location = 1; }
Vector3 Listener::toLocalDirection ( Vector3  dir) const
throw (
)

Return the direction 'dir' in a local coordinate system centered at the listener's position, with the -Z axis pointing forward, +X pointing rightward and +Y pointing upwards (the OpenGL way).

Note
The attributes used are those set during the last update()
The behavior is unspecified if there was no previous call to update().

Definition at line 68 of file Listener.cpp.

69  {
70  return worldToLocal * dir;
71  }
void Listener::update ( int  flags)
throw (
)
See Also
RenderableListener::update
Parameters
flagssee RenderableListener::UpdateFlags
Note
It's not just a convenience, the abstract listener has to update its internal dirty flags and other things as well.

Definition at line 41 of file Listener.cpp.

References Audio::RenderableListener::update(), Audio::RenderableListener::UPDATE_ATTRIBUTES, Audio::RenderableListener::UPDATE_GAIN, and Audio::RenderableListener::UPDATE_LOCATION.

42  {
43  if (!dirty.attributes)
44  flags &= ~RenderableListener::UPDATE_ATTRIBUTES;
45  if (!dirty.location)
46  flags &= ~RenderableListener::UPDATE_LOCATION;
47  if (!dirty.gain)
48  flags &= ~RenderableListener::UPDATE_GAIN;
49 
50  if (getRenderable().get() != 0)
51  getRenderable()->update(flags);
52 
54  dirty.attributes = 0;
56  dirty.gain = 0;
58  worldToLocal =
59  Matrix3(
60  atDirection.cross(upDirection),
61  upDirection,
62  -atDirection
63  ).inverse();
64  dirty.location = 0;
65  }
66  }

Member Data Documentation


The documentation for this class was generated from the following files: