1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_Sound3DListener.cpp
4
5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain proprietary
8 information of Nintendo and/or its licensed developers and are protected by
9 national and international copyright laws. They may not be disclosed to third
10 parties or copied or duplicated in any form, in whole or in part, without the
11 prior written consent of Nintendo.
12
13 The content herein is highly confidential and should be handled accordingly.
14
15 $Revision: $
16 *---------------------------------------------------------------------------*/
17
18 #include "precompiled.h"
19
20 #include <nw/snd/snd_Sound3DListener.h>
21
22 namespace nw {
23 namespace snd {
24
25 /*---------------------------------------------------------------------------*
26 Name: Sound3DListener
27
28 Description: コンストラクタ
29
30 Arguments: None.
31
32 Returns: None.
33 *---------------------------------------------------------------------------*/
Sound3DListener()34 Sound3DListener::Sound3DListener()
35 : m_Position( 0.0f, 0.0f, 0.0f ),
36 m_Velocity( 0.0f, 0.0f, 0.0f ),
37 m_InteriorSize( 1.0f ),
38 m_MaxVolumeDistance( 1.0f ),
39 m_UnitDistance( 1.0f ),
40 m_UserParam( 0 ),
41 m_UnitBiquadFilterValue( 0.5f ),
42 m_MaxBiquadFilterValue( 1.0f ),
43 m_ResetMatrixFlag( true )
44 {
45 nw::math::MTX34Zero( &m_Mtx );
46 }
47
SetMatrix(const nw::math::MTX34 & mtx)48 void Sound3DListener::SetMatrix( const nw::math::MTX34& mtx )
49 {
50 nw::math::VEC3 oldPos = m_Position;
51 CalcPositionFromMatrix( mtx, &m_Position );
52
53 if ( m_ResetMatrixFlag ) {
54 m_Mtx = mtx;
55 m_ResetMatrixFlag = false;
56 }
57 else {
58 m_Mtx = mtx;
59 nw::math::VEC3Sub( &m_Velocity, &m_Position, &oldPos );
60 }
61 }
62
CalcPositionFromMatrix(const nw::math::MTX34 & mtx,nw::math::VEC3 * pos)63 void Sound3DListener::CalcPositionFromMatrix( const nw::math::MTX34& mtx, nw::math::VEC3* pos )
64 {
65 pos->x = -( mtx.f._00 * mtx.f._03 + mtx.f._10 * mtx.f._13 + mtx.f._20 * mtx.f._23 );
66 pos->y = -( mtx.f._01 * mtx.f._03 + mtx.f._11 * mtx.f._13 + mtx.f._21 * mtx.f._23 );
67 pos->z = -( mtx.f._02 * mtx.f._03 + mtx.f._12 * mtx.f._13 + mtx.f._22 * mtx.f._23 );
68 }
69
ResetMatrix()70 void Sound3DListener::ResetMatrix()
71 {
72 nw::math::MTX34Zero( &m_Mtx );
73 m_Velocity = nw::math::VEC3( 0.0f,0.0f,0.0f );
74 m_ResetMatrixFlag = true;
75 }
76
SetVelocity(const nw::math::VEC3 & velocity)77 void Sound3DListener::SetVelocity( const nw::math::VEC3& velocity )
78 {
79 m_Velocity = velocity;
80 }
81
SetInteriorSize(f32 interiorSize)82 void Sound3DListener::SetInteriorSize( f32 interiorSize )
83 {
84 NW_ASSERT( interiorSize > 0.0f );
85 m_InteriorSize = interiorSize;
86 }
87
SetMaxVolumeDistance(f32 maxVolumeDistance)88 void Sound3DListener::SetMaxVolumeDistance( f32 maxVolumeDistance )
89 {
90 NW_ASSERT( maxVolumeDistance >= 0.0f );
91 m_MaxVolumeDistance = maxVolumeDistance;
92 }
93
SetUnitDistance(f32 unitDistance)94 void Sound3DListener::SetUnitDistance( f32 unitDistance )
95 {
96 NW_ASSERT( unitDistance > 0.0f );
97 m_UnitDistance = unitDistance;
98 }
99
SetUnitBiquadFilterValue(f32 value)100 void Sound3DListener::SetUnitBiquadFilterValue( f32 value )
101 {
102 NW_MINMAX_ASSERT( value, 0.0f, 1.0f );
103 m_UnitBiquadFilterValue = value;
104 }
105
SetMaxBiquadFilterValue(f32 value)106 void Sound3DListener::SetMaxBiquadFilterValue( f32 value )
107 {
108 NW_MINMAX_ASSERT( value, 0.0f, 1.0f );
109 m_MaxBiquadFilterValue = value;
110 }
111
112 } // namespace nw::snd
113 } // namespace nw
114
115