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