Unit1.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLBaseClasses"
  8. #pragma link "GLCadencer"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLGeomObjects"
  12. #pragma link "GLObjects"
  13. #pragma link "GLScene"
  14. #pragma link "GLSMBASS"
  15. #pragma link "GLSMFMOD"
  16. #pragma link "GLSMOpenAL"
  17. #pragma link "GLSound"
  18. #pragma link "GLWin32Viewer"
  19. #pragma link "GLFileWAV"
  20. #pragma link "GLFileMP3"
  21. #pragma resource "*.dfm"
  22. TForm1 *Form1;
  23. int mx,my;
  24. //---------------------------------------------------------------------------
  25. __fastcall TForm1::TForm1(TComponent* Owner)
  26. : TForm(Owner)
  27. {
  28. }
  29. //---------------------------------------------------------------------------
  30. void __fastcall TForm1::FormCreate(TObject *Sender)
  31. {
  32. SetGLSceneMediaDir();
  33. // Load our sound sample
  34. GLSoundLibrary->Samples->AddFile("drumloop.wav","drumloop.wav");
  35. GLSoundLibrary->Samples->AddFile("chimes.wav","chimes.wav");
  36. GLSoundLibrary->Samples->AddFile("howl.mp3","howl.mp3");
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TForm1::SphereProgress(TObject *Sender, const double deltaTime, const double newTime)
  40. {
  41. Single alpha;
  42. // Move the red sphere (sound source) along an elliptic path
  43. alpha = 60*DegToRad(newTime);
  44. ((TGLSphere *) Sender)->Position->SetPoint(sin(alpha)*2, 0.5, cos(alpha)*5);
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::TrackBar1Change(TObject *Sender)
  48. {
  49. // Move the listener forward/back
  50. Mickey->Position->Z = TrackBar1->Position/10;
  51. Application->ProcessMessages();
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::TrackBarChange(TObject *Sender)
  55. {
  56. // Rotate the listener around the vertical axis
  57. DummyCube->TurnAngle = TrackBar->Position;
  58. Application->ProcessMessages();
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TForm1::Button1Click(TObject *Sender)
  62. {
  63. TGLBSoundEmitter *se = new TGLBSoundEmitter(Sphere->Behaviours);
  64. se->Source->SoundLibrary = GLSoundLibrary;
  65. se->Source->SoundName = "chimes.wav";
  66. se->Playing = True;
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::btnHowlClick(TObject *Sender)
  70. {
  71. TGLBSoundEmitter *se = new TGLBSoundEmitter(Sphere->Behaviours);
  72. se->Source->SoundLibrary = GLSoundLibrary;
  73. se->Source->SoundName = "howl.mp3";
  74. se->Playing = True;
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::TimerTimer(TObject *Sender)
  78. {
  79. String mngName;
  80. TGLSoundManager *sm;
  81. sm = ActiveSoundManager();
  82. // some stats
  83. if(dynamic_cast < TGLSMBASS * >(sm))
  84. mngName = "BASS";
  85. else if(dynamic_cast < TGLSMFMOD * >(sm))
  86. mngName = "FMOD";
  87. else if (dynamic_cast < TGLSMOpenAL * >(sm))
  88. mngName = "OpenAL";
  89. else
  90. mngName = "";
  91. if(sm)
  92. LabelFPS->Caption = Format("%.2f FPS, %s CPU use : %.2f%%",
  93. ARRAYOFCONST((GLSceneViewer->FramesPerSecond(), mngName,
  94. ActiveSoundManager()->CPUUsagePercent())));
  95. else
  96. LabelFPS->Caption = "No active sound manager.";
  97. GLSceneViewer->ResetPerformanceMonitor();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TForm1::RBFMODClick(TObject *Sender)
  101. {
  102. TGLSoundManager *newManager, *sm;
  103. // This method switches managers. On a real world project, this would never
  104. // happen: you would choose and API and then cling to it, but the GLSS
  105. // completely wraps the underlying complexity and makes it a snap
  106. if(RBFMOD->Checked)
  107. newManager = GLSMFMOD;
  108. else
  109. newManager = GLSMBASS;
  110. sm = ActiveSoundManager();
  111. if(newManager != sm)
  112. {
  113. // shut down current one, and activate the new one
  114. if(sm)
  115. {
  116. sm->Active = False;
  117. newManager->Active = True;
  118. // restart sound
  119. GetOrCreateSoundEmitter(Sphere)->Playing = True;
  120. }
  121. }
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TForm1::GLSceneViewerMouseMove(TObject *Sender, TShiftState Shift,
  125. int X, int Y)
  126. {
  127. if(Shift.Contains(ssLeft))
  128. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  129. else if(Shift.Contains(ssRight))
  130. GLCamera1->AdjustDistanceToTarget(1 + (my - Y) * 0.01);
  131. mx = X;
  132. my = Y;
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TForm1::GLSceneViewerMouseDown(TObject *Sender, TMouseButton Button,
  136. TShiftState Shift, int X, int Y)
  137. {
  138. mx = X; my = Y;
  139. }
  140. //---------------------------------------------------------------------------