fBoomC.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fBoomC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Behaviours"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.FireFX"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma resource "*.dfm"
  16. TFormBoom* FormBoom;
  17. //---------------------------------------------------------------------------
  18. __fastcall TFormBoom::TFormBoom(TComponent* Owner) : TForm(Owner) {}
  19. //---------------------------------------------------------------------------
  20. void __fastcall TFormBoom::Button1Click(TObject* Sender)
  21. {
  22. // A button click triggers the small animation sequence
  23. // first, we enabled the cadencer, to get Progression events
  24. GLCadencer1->Enabled = True;
  25. // then we set (or reset) the sphere position and initial speed
  26. Sphere1->Position->AsVector = NullHmgPoint;
  27. GetOrCreateInertia(Sphere1)->TranslationSpeed->SetVector(
  28. Random(), 9, Random());
  29. // the tagfloat is used as timer (before explosion)
  30. Sphere1->TagFloat = 3.5;
  31. // Here we reinitialize the FireFX (starts enabled) and SmokeFX (disabled at first)
  32. FireFX->ParticleSize = 0.5;
  33. FireFX->Disabled = false;
  34. FireFX->FireInit();
  35. SmokeFX->Disabled = true;
  36. SmokeFX->FireInit();
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TFormBoom::GLCadencer1Progress(
  40. TObject* Sender, const double deltaTime, const double newTime)
  41. {
  42. // have we exploded yet?
  43. if (Sphere1->TagFloat > 0) {
  44. // no, so decrease time before explosion
  45. Sphere1->TagFloat = Sphere1->TagFloat - deltaTime;
  46. // explosion time?
  47. if (Sphere1->TagFloat < 0) {
  48. // yep! make particles bigger,
  49. FireFX->ParticleSize = 2;
  50. // fire the explosion
  51. if (Random() > 0.5)
  52. FireFX->IsotropicExplosion(8, 10, 5);
  53. else
  54. FireFX->RingExplosion(8, 10, 5, XVector, ZVector);
  55. // stop the fire trail
  56. FireFX->Disabled = true;
  57. // and start the smoke trail
  58. SmokeFX->Disabled = false;
  59. }
  60. }
  61. // A gravity-like acceleration is applied to the sphere
  62. GetOrCreateInertia(Sphere1)->ApplyTranslationAcceleration(
  63. deltaTime, VectorMake(0, -2, 0));
  64. // restart effect when sphere fell too low
  65. if (Sphere1->Position->Y < -2)
  66. Button1Click(this);
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TFormBoom::Timer1Timer(TObject* Sender)
  70. {
  71. // standard issue framerate & particle count update
  72. Caption =
  73. "Boom - " + Format("%.1f FPS - %d Particles",
  74. ARRAYOFCONST((GLSceneViewer1->FramesPerSecond(),
  75. FireFX->ParticleCount + SmokeFX->ParticleCount)));
  76. GLSceneViewer1->ResetPerformanceMonitor();
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TFormBoom::FormResize(TObject* Sender)
  80. {
  81. // take care of zooming if window is resize
  82. GLCamera1->FocalLength = Width * 0.1;
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TFormBoom::GLSceneViewer1MouseMove(
  86. TObject* Sender, TShiftState Shift, int X, int Y)
  87. {
  88. if (Shift.Contains(ssLeft) || Shift.Contains(ssRight)) {
  89. // move around target
  90. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  91. mx = X;
  92. my = Y;
  93. GLCadencer1->Progress();
  94. }
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TFormBoom::GLSceneViewer1MouseDown(
  98. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  99. {
  100. mx = X;
  101. my = Y;
  102. }
  103. //---------------------------------------------------------------------------