2
0

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