OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / directsound / SoundListener3D.cpp
1 #include "stdafx.h"
2 /*
3 * Copyright (c) 2007-2010 SlimDX Group
4
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:
11
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14
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
21 * THE SOFTWARE.
22 */
23 #include <windows.h>
24 #include <dsound.h>
25
26 #include "../ComObject.h"
27 #include "../math/Vector3.h"
28
29 #include "DirectSoundException.h"
30
31 #include "DirectSound.h"
32
33 #include "SoundBuffer.h"
34 #include "SoundListener3D.h"
35
36 using namespace System;
37
38 namespace SlimDX
39 {
40 namespace DirectSound
41 {
42         SoundListener3D::SoundListener3D( SoundBuffer^ soundBuffer )
43         {
44                 IDirectSound3DListener8* listener;
45
46                 HRESULT hr = soundBuffer->InternalPointer->QueryInterface( IID_IDirectSound3DListener8, reinterpret_cast<void**>( &listener ) );
47                 if( RECORD_DSOUND( hr ).IsFailure )
48                         throw gcnew DirectSoundException( Result::Last );
49                 
50                 Construct( listener );
51         }
52
53         Result SoundListener3D::CommitDeferredSettings()
54         {
55                 HRESULT hr = InternalPointer->CommitDeferredSettings();
56                 return RECORD_DSOUND( hr );
57         }
58
59         float SoundListener3D::DistanceFactor::get()
60         {
61                 float distance = 0.0f;
62                 HRESULT hr = InternalPointer->GetDistanceFactor( &distance );
63                 RECORD_DSOUND( hr );
64
65                 return distance;
66         }
67
68         void SoundListener3D::DistanceFactor::set( float value )
69         {
70                 HRESULT hr = InternalPointer->SetDistanceFactor( value, Deferred ?  DS3D_DEFERRED : DS3D_IMMEDIATE );
71                 RECORD_DSOUND( hr );
72         }
73
74         float SoundListener3D::DopplerFactor::get()
75         {
76                 float doppler = 0.0f;
77                 HRESULT hr = InternalPointer->GetDopplerFactor( &doppler );
78                 RECORD_DSOUND( hr );
79
80                 return doppler;
81         }
82
83         void SoundListener3D::DopplerFactor::set( float value )
84         {
85                 HRESULT hr = InternalPointer->SetDopplerFactor( value, Deferred ?  DS3D_DEFERRED : DS3D_IMMEDIATE );
86                 RECORD_DSOUND( hr );
87         }
88
89         float SoundListener3D::RolloffFactor::get()
90         {
91                 float rolloff = 0.0f;
92                 HRESULT hr = InternalPointer->GetRolloffFactor( &rolloff );
93                 RECORD_DSOUND( hr );
94
95                 return rolloff;
96         }
97
98         void SoundListener3D::RolloffFactor::set( float value )
99         {
100                 HRESULT hr = InternalPointer->SetRolloffFactor( value, Deferred ?  DS3D_DEFERRED : DS3D_IMMEDIATE );
101                 RECORD_DSOUND( hr );
102         }
103
104         Vector3 SoundListener3D::FrontOrientation::get()
105         {
106                 D3DVECTOR front = D3DVECTOR();
107                 D3DVECTOR top = D3DVECTOR();
108                 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
109
110                 if( RECORD_DSOUND( hr ).IsFailure )
111                         return Vector3::Zero;
112
113                 return Vector3( front.x, front.y, front.z );
114         }
115
116         Vector3 SoundListener3D::TopOrientation::get()
117         {
118                 D3DVECTOR front = D3DVECTOR();
119                 D3DVECTOR top = D3DVECTOR();
120                 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
121
122                 if( RECORD_DSOUND( hr ).IsFailure )
123                         return Vector3::Zero;
124
125                 return Vector3( top.x, top.y, top.z );
126         }
127
128         void SoundListener3D::FrontOrientation::set( Vector3 value )
129         {
130                 D3DVECTOR front = D3DVECTOR();
131                 D3DVECTOR top = D3DVECTOR();
132                 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
133
134                 if( RECORD_DSOUND( hr ).IsFailure )
135                         return;
136
137                 hr = InternalPointer->SetOrientation( value.X, value.Y, value.Z, top.x, top.y, top.z,
138                         Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
139                 RECORD_DSOUND( hr );
140         }
141
142         void SoundListener3D::TopOrientation::set( Vector3 value )
143         {
144                 D3DVECTOR front = D3DVECTOR();
145                 D3DVECTOR top = D3DVECTOR();
146                 HRESULT hr = InternalPointer->GetOrientation( &front, &top );
147
148                 if( RECORD_DSOUND( hr ).IsFailure )
149                         return;
150
151                 hr = InternalPointer->SetOrientation( front.x, front.y, front.z, value.X, value.Y, value.Z,
152                         Deferred ? DS3D_DEFERRED : DS3D_IMMEDIATE );
153                 RECORD_DSOUND( hr );
154         }
155
156         Vector3 SoundListener3D::Position::get()
157         {
158                 D3DVECTOR position = D3DVECTOR();
159                 HRESULT hr = InternalPointer->GetPosition( &position );
160                 RECORD_DSOUND( hr );
161
162                 return Vector3( position.x, position.y, position.z );
163         }
164
165         void SoundListener3D::Position::set( Vector3 value )
166         {
167                 HRESULT hr = InternalPointer->SetPosition( value.X, value.Y, value.Z, Deferred ?  DS3D_DEFERRED : DS3D_IMMEDIATE );
168                 RECORD_DSOUND( hr );
169         }
170
171         Vector3 SoundListener3D::Velocity::get()
172         {
173                 D3DVECTOR velocity = D3DVECTOR();
174                 HRESULT hr = InternalPointer->GetVelocity( &velocity );
175                 RECORD_DSOUND( hr );
176
177                 return Vector3( velocity.x, velocity.y, velocity.z );
178         }
179
180         void SoundListener3D::Velocity::set( Vector3 value )
181         {
182                 HRESULT hr = InternalPointer->SetVelocity( value.X, value.Y, value.Z, Deferred ?  DS3D_DEFERRED : DS3D_IMMEDIATE );
183                 RECORD_DSOUND( hr );
184         }
185 }
186 }