Unit1.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 "Unit1.h"
  8. //---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "GLBaseClasses"
  11. #pragma link "GLBehaviours"
  12. #pragma link "GLCadencer"
  13. #pragma link "GLCoordinates"
  14. #pragma link "GLCrossPlatform"
  15. #pragma link "GLObjects"
  16. #pragma link "GLParticles"
  17. #pragma link "GLScene"
  18. #pragma link "GLWin32Viewer"
  19. #pragma resource "*.dfm"
  20. TForm1 *Form1;
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm1::TForm1(TComponent* Owner)
  23. : TForm(Owner)
  24. {
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::GLParticles1ActivateParticle(TObject *Sender, TGLBaseSceneObject *particle)
  28. {
  29. float r, alpha, cr, sr;
  30. alpha = Random()*2*M_PI;
  31. r = 2*Random();
  32. SinCosine(alpha, r*r, sr, cr);
  33. particle->Children[0]->Position->SetPoint(sr, 3*r-3, cr);
  34. GetOrCreateInertia(particle)->TurnSpeed = Random(30);
  35. particle->TagFloat = GLCadencer1->CurrentTime;
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  39. TShiftState Shift, int X, int Y)
  40. {
  41. mx = X; my = Y;
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  45. int X, int Y)
  46. {
  47. if (Shift.Contains(ssLeft))
  48. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  49. mx = X;
  50. my = Y;
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::GLDummyCube1Progress(TObject *Sender, const double deltaTime,
  54. const double newTime)
  55. {
  56. if (newTime-(GLParticles1->TagFloat)>3)
  57. GLParticles1->KillParticle(GLParticles1);
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  61. const double newTime)
  62. {
  63. GLParticles1->CreateParticle();
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  67. {
  68. Panel1->Caption = Format("%d particles, %.1f FPS",
  69. ARRAYOFCONST((GLParticles1->Count, GLSceneViewer1->FramesPerSecond())));
  70. GLSceneViewer1->ResetPerformanceMonitor();
  71. }
  72. //---------------------------------------------------------------------------