Unit1.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.SceneViewer"
  8. #pragma link "GLS.VectorGeometry"
  9. #pragma link "GLS.Behaviours"
  10. #pragma link "GLS.SceneViewer"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.Cadencer"
  14. #pragma link "GLS.ParticleFX"
  15. #pragma link "GLS.BaseClasses"
  16. #pragma link "GLS.Coordinates"
  17. #pragma link "GLFullScreenViewer"
  18. #pragma resource "*.dfm"
  19. TForm1 *Form1;
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent * Owner):TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::TimerTimer(TObject * Sender)
  26. {
  27. // Display FPS and particle count in the form's caption
  28. Caption = "Spiral - " +
  29. Format("%d Particles - %.1f FPS",
  30. ARRAYOFCONST((PFXRing->Particles->ItemCount() +
  31. PFXSpiral->Particles->ItemCount(),GLSceneViewer->FramesPerSecond())));
  32. GLSceneViewer->ResetPerformanceMonitor();
  33. // Alternatively trigger a "sphere" or "ring" explosion
  34. //
  35. TGLSourcePFXEffect *e;
  36. Timer->Tag = Timer->Tag + 1;
  37. if((Timer->Tag & 1) != 0)
  38. {
  39. // "Sphere" explosion
  40. e = GetOrCreateSourcePFX(DCBase,"");
  41. e->VelocityDispersion = 1.5;
  42. e->Burst(GLCadencer->CurrentTime, 200);
  43. e->VelocityDispersion = 0;
  44. }
  45. else
  46. {
  47. // Ring explosion
  48. GetOrCreateSourcePFX(DCBase,"")->RingExplosion(GLCadencer->CurrentTime, 1, 1.2,
  49. 150);
  50. }
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::FormResize(TObject * Sender)
  54. {
  55. // Rescale when window is resized
  56. GLCamera->SceneScale = GLSceneViewer->Height / 350;
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::GLSceneViewerDblClick(TObject * Sender)
  60. {
  61. // Switch to full-screen, but using the same screen resolution
  62. // if(you uncomment the line below, it will switch to 800x600x32
  63. GLFullScreenViewer->UseCurrentResolution();
  64. GLFullScreenViewer->Active = True;
  65. // Hide the windows viewer so it is no longer updated
  66. GLSceneViewer->Visible = False;
  67. // Apply proper scale
  68. GLCamera->SceneScale = GLFullScreenViewer->Height / 350;
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::GLFullScreenViewerDblClick(TObject * Sender)
  72. {
  73. // Make the windows viewer visible again
  74. GLSceneViewer->Visible = True;
  75. // Deactivate full-screen mode
  76. GLFullScreenViewer->Active = False;
  77. // And apply back the adequate scale for the SceneViewer
  78. FormResize(this);
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::GLFullScreenViewerKeyPress(TObject * Sender, char &Key)
  82. {
  83. // Hitting 'ESC' has same effect as a double-click
  84. // (the FullScreenViewer has several Form-like events)
  85. if(Key == 0x27)
  86. {
  87. GLFullScreenViewerDblClick(this);
  88. Key = '\0';
  89. }
  90. }
  91. //---------------------------------------------------------------------------
  92. void __fastcall TForm1::GLSceneViewerMouseMove(TObject * Sender,
  93. TShiftState Shift, int X, int Y)
  94. {
  95. // Mouse moved in the Viewer (windowed or fullscreen mode)
  96. if(Shift.Contains(ssRight))
  97. GLCamera->Position->Y =
  98. ((float)GLScene->CurrentBuffer->Height() / 2.0 -
  99. Y) * 0.1 / GLCamera->SceneScale;
  100. // Ensures we don't flood the event system with mouse moves (high priority events)
  101. // and ) prevent the cadencer from progressing (low priority events)
  102. GLCadencer->Progress();
  103. }
  104. //---------------------------------------------------------------------------