3 * Copyright (c) 2007-2010 SlimDX Group
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "../ComObject.h"
27 #include "../math/Vector3.h"
29 #include "DirectSoundException.h"
31 #include "DirectSound.h"
33 #include "SoundBuffer.h"
34 #include "SoundListener3D.h"
36 using namespace System;
42 SoundListener3D::SoundListener3D( SoundBuffer^ soundBuffer )
44 IDirectSound3DListener8* listener;
46 HRESULT hr = soundBuffer->InternalPointer->QueryInterface( IID_IDirectSound3DListener8, reinterpret_cast<void**>( &listener ) );
47 if( RECORD_DSOUND( hr ).IsFailure )
48 throw gcnew DirectSoundException( Result::Last );
50 Construct( listener );
53 Result SoundListener3D::CommitDeferredSettings()
55 HRESULT hr = InternalPointer->CommitDeferredSettings();
56 return RECORD_DSOUND( hr );
59 float SoundListener3D::DistanceFactor::get()
61 float distance = 0.0f;
62 HRESULT hr = InternalPointer->GetDistanceFactor( &distance );
68 void SoundListener3D::DistanceFactor::set( float value )
70 HRESULT hr = InternalPointer->SetDistanceFactor( value, Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
74 float SoundListener3D::DopplerFactor::get()
77 HRESULT hr = InternalPointer->GetDopplerFactor( &doppler );
83 void SoundListener3D::DopplerFactor::set( float value )
85 HRESULT hr = InternalPointer->SetDopplerFactor( value, Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
89 float SoundListener3D::RolloffFactor::get()
92 HRESULT hr = InternalPointer->GetRolloffFactor( &rolloff );
98 void SoundListener3D::RolloffFactor::set( float value )
100 HRESULT hr = InternalPointer->SetRolloffFactor( value, Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
104 Vector3 SoundListener3D::FrontOrientation::get()
106 D3DVECTOR front = D3DVECTOR();
107 D3DVECTOR top = D3DVECTOR();
108 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
110 if( RECORD_DSOUND( hr ).IsFailure )
111 return Vector3::Zero;
113 return Vector3( front.x, front.y, front.z );
116 Vector3 SoundListener3D::TopOrientation::get()
118 D3DVECTOR front = D3DVECTOR();
119 D3DVECTOR top = D3DVECTOR();
120 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
122 if( RECORD_DSOUND( hr ).IsFailure )
123 return Vector3::Zero;
125 return Vector3( top.x, top.y, top.z );
128 void SoundListener3D::FrontOrientation::set( Vector3 value )
130 D3DVECTOR front = D3DVECTOR();
131 D3DVECTOR top = D3DVECTOR();
132 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
134 if( RECORD_DSOUND( hr ).IsFailure )
137 hr = InternalPointer->SetOrientation( value.X, value.Y, value.Z, top.x, top.y, top.z,
138 Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
142 void SoundListener3D::TopOrientation::set( Vector3 value )
144 D3DVECTOR front = D3DVECTOR();
145 D3DVECTOR top = D3DVECTOR();
146 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
148 if( RECORD_DSOUND( hr ).IsFailure )
151 hr = InternalPointer->SetOrientation( front.x, front.y, front.z, value.X, value.Y, value.Z,
152 Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
156 Vector3 SoundListener3D::Position::get()
158 D3DVECTOR position = D3DVECTOR();
159 HRESULT hr = InternalPointer->GetPosition( &position );
162 return Vector3( position.x, position.y, position.z );
165 void SoundListener3D::Position::set( Vector3 value )
167 HRESULT hr = InternalPointer->SetPosition( value.X, value.Y, value.Z, Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
171 Vector3 SoundListener3D::Velocity::get()
173 D3DVECTOR velocity = D3DVECTOR();
174 HRESULT hr = InternalPointer->GetVelocity( &velocity );
177 return Vector3( velocity.x, velocity.y, velocity.z );
180 void SoundListener3D::Velocity::set( Vector3 value )
182 HRESULT hr = InternalPointer->SetVelocity( value.X, value.Y, value.Z, Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );