fWhirlC.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #include <system.hpp>
  5. #include <math.hpp>
  6. #pragma hdrstop
  7. #include "fWhirlC.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "GLS.BaseClasses"
  11. #pragma link "GLS.Behaviours"
  12. #pragma link "GLS.Cadencer"
  13. #pragma link "GLS.Coordinates"
  14. #pragma link "GLS.Objects"
  15. #pragma link "GLS.Particles"
  16. #pragma link "GLS.Scene"
  17. #pragma link "GLS.SceneViewer"
  18. #pragma resource "*.dfm"
  19. TFormWhirlC *FormWhirlC;
  20. //---------------------------------------------------------------------------
  21. __fastcall TFormWhirlC::TFormWhirlC(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TFormWhirlC::GLParticles1ActivateParticle(TObject *Sender, TGLBaseSceneObject *particle)
  27. {
  28. float r, alpha, cr, sr;
  29. alpha = Random()*2*M_PI;
  30. r = 2*Random();
  31. SinCosine(alpha, r*r, sr, cr);
  32. particle->Children[0]->Position->SetPoint(sr, 3*r-3, cr);
  33. GetOrCreateInertia(particle)->TurnSpeed = Random(30);
  34. particle->TagFloat = GLCadencer1->CurrentTime;
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TFormWhirlC::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  38. TShiftState Shift, int X, int Y)
  39. {
  40. mx = X; my = Y;
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TFormWhirlC::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  44. int X, int Y)
  45. {
  46. if (Shift.Contains(ssLeft))
  47. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  48. mx = X;
  49. my = Y;
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TFormWhirlC::GLDummyCube1Progress(TObject *Sender, const double deltaTime,
  53. const double newTime)
  54. {
  55. if (newTime-(GLParticles1->TagFloat)>3)
  56. GLParticles1->KillParticle(GLParticles1);
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TFormWhirlC::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  60. const double newTime)
  61. {
  62. GLParticles1->CreateParticle();
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TFormWhirlC::Timer1Timer(TObject *Sender)
  66. {
  67. Panel1->Caption = Format("%d particles, %.1f FPS",
  68. ARRAYOFCONST((GLParticles1->Count, GLSceneViewer1->FramesPerSecond())));
  69. GLSceneViewer1->ResetPerformanceMonitor();
  70. }
  71. //---------------------------------------------------------------------------