home *** CD-ROM | disk | FTP | other *** search
/ Game Audio Programming / GameAudioProgramming.iso / Game_Audio / AudioTest / Listener.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-07-06  |  3.5 KB  |  138 lines

  1. /***********************************************************\
  2. Copyright (C) James Boer, 2002. 
  3. All rights reserved worldwide.
  4.  
  5. This software is provided "as is" without express or implied
  6. warranties. You may freely copy and compile this source into
  7. applications you distribute provided that the copyright text
  8. below is included in the resulting source code, for example:
  9. "Portions Copyright (C) James Boer, 2002"
  10. \***********************************************************/
  11.  
  12. #include "stdafx.h"
  13. #include "audiotest.h"
  14. #include "Listener.h"
  15. #include "EAXListener.h"
  16.  
  17. #include "AudioTestDlg.h"
  18. #include "System.h"
  19. #include "Sound2D.h"
  20. #include "Sound3D.h"
  21. #include "Segment.h"
  22.  
  23. using namespace Audio;
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CListener property page
  33.  
  34. IMPLEMENT_DYNCREATE(CListener, CPropertyPage)
  35.  
  36. CListener::CListener() : CPropertyPage(CListener::IDD)
  37. {
  38.     //{{AFX_DATA_INIT(CListener)
  39.         // NOTE: the ClassWizard will add member initialization here
  40.     //}}AFX_DATA_INIT
  41.     m_pListener = 0;
  42. }
  43.  
  44. CListener::~CListener()
  45. {
  46. }
  47.  
  48. void CListener::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CPropertyPage::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CListener)
  52.     DDX_Control(pDX, IDC_SLIDER_LISTENER_POSZ, m_ZPos);
  53.     DDX_Control(pDX, IDC_SLIDER_LISTENER_POSY, m_YPos);
  54.     DDX_Control(pDX, IDC_SLIDER_LISTENER_POSX, m_XPos);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58.  
  59. BEGIN_MESSAGE_MAP(CListener, CPropertyPage)
  60.     //{{AFX_MSG_MAP(CListener)
  61.     ON_WM_DESTROY()
  62.     ON_BN_CLICKED(IDC_LISTENER_EAX, OnListenerEAX)
  63.     ON_WM_HSCROLL()
  64.     //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66.  
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CListener message handlers
  69.  
  70.  
  71.  
  72. BOOL CListener::OnInitDialog() 
  73. {
  74.     CPropertyPage::OnInitDialog();
  75.     
  76.     if(AudioMgr()->IsInitialized())
  77.         AudioMgr()->GetListener(m_pListener);
  78.     
  79.     m_XPos.SetRange(0, 10000, TRUE);
  80.     m_YPos.SetRange(0, 10000, TRUE);
  81.     m_ZPos.SetRange(0, 10000, TRUE);
  82.     m_XPos.SetPos(5000);
  83.     m_YPos.SetPos(5000);
  84.     m_ZPos.SetPos(5000);
  85.  
  86.     return TRUE;  // return TRUE unless you set the focus to a control
  87.                   // EXCEPTION: OCX Property Pages should return FALSE
  88. }
  89.  
  90. void CListener::OnDestroy() 
  91. {
  92.     CPropertyPage::OnDestroy();
  93. }
  94.  
  95. void CListener::OnListenerEAX() 
  96. {
  97.     if(!m_pTestDlg->m_pEAXListener)
  98.     {
  99.         m_pTestDlg->m_pEAXListener = new CEAXListener;
  100.         m_pTestDlg->m_pEAXListener->m_pTestDlg = m_pTestDlg;
  101.         m_pTestDlg->m_pEAXListener->Create(IDD_EAX_LISTENER, this);
  102.         m_pTestDlg->m_pEAXListener->ShowWindow(SW_SHOW);
  103.     }
  104.  
  105. }
  106.  
  107. void CListener::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  108. {
  109.     if(pScrollBar->IsKindOf(RUNTIME_CLASS(CSliderCtrl)))
  110.     {
  111.         CSliderCtrl* pSlider = reinterpret_cast<CSliderCtrl*>(pScrollBar);
  112.         if(!pSlider)
  113.             return;
  114.         if(pSlider == &m_XPos)
  115.         {
  116.             AUDIOVECTOR pos;
  117.             m_pListener->GetPosition(pos);
  118.             pos.x = ((float(pSlider->GetPos()) - 5000.0f) / 10000.0f) * 20.0f;
  119.             m_pListener->SetPosition(pos);
  120.         }
  121.         else if(pSlider == &m_YPos)
  122.         {
  123.             AUDIOVECTOR pos;
  124.             m_pListener->GetPosition(pos);
  125.             pos.y = ((float(pSlider->GetPos()) - 5000.0f) / 10000.0f) * 20.0f;
  126.             m_pListener->SetPosition(pos);
  127.         }
  128.         else if(pSlider == &m_ZPos)
  129.         {
  130.             AUDIOVECTOR pos;
  131.             m_pListener->GetPosition(pos);
  132.             pos.z = ((float(pSlider->GetPos()) - 5000.0f) / 10000.0f) * 20.0f;
  133.             m_pListener->SetPosition(pos);
  134.         }
  135.     }
  136.     CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  137. }
  138.