Unit1.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLBaseClasses"
  9. #pragma link "GLCadencer"
  10. #pragma link "GLCoordinates"
  11. #pragma link "GLCrossPlatform"
  12. #pragma link "GLObjects"
  13. #pragma link "GLScene"
  14. #pragma link "GLSceneViewer"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. const int
  18. cNbPoints = 200;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::FormCreate(TObject *Sender)
  26. {
  27. // allocate points in the 1st point set
  28. GLPoints1->Positions->Count = cNbPoints;
  29. // specify white color for the 1st point set
  30. // (if a single color is defined, all points will use it,
  31. // otherwise, it's a per-point coloring)
  32. GLPoints1->Colors->Add(clrWhite);
  33. // specify blue color for the 2nd point set
  34. GLPoints2->Colors->Add(clrBlue);
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  38. const double newTime)
  39. {
  40. int i;
  41. float f, a, ab, ca, sa;
  42. TAffineVectorList *p;
  43. TAffineVector *v;
  44. p = new TAffineVectorList;
  45. v = new TAffineVector;
  46. if (CBAnimate->Checked)
  47. {
  48. // update the 1st point set with values from a math func
  49. f = 1+Cos(newTime);
  50. p = GLPoints1->Positions;
  51. ab = newTime*0.1;
  52. for (i=0; i < cNbPoints-1; i++) {
  53. a = DegToRad((float)4*i)+ ab;
  54. SinCos(a, sa, ca);
  55. v->X = 2*ca;
  56. v->Y = 2*Cos(f*a);
  57. v->Z = 2*sa;
  58. p->Items[i] = *v;
  59. }
  60. // replicate points in second set
  61. GLPoints2->Positions = GLPoints1->Positions;
  62. }
  63. GLSceneViewer1->Invalidate();
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  67. TShiftState Shift, int X, int Y)
  68. {
  69. mx = X; my = Y;
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  73. int X, int Y)
  74. {
  75. if (Shift.Contains(ssLeft) || Shift.Contains(ssRight))
  76. {
  77. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  78. mx =X;
  79. my =Y;
  80. }
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TForm1::CBAnimateClick(TObject *Sender)
  84. {
  85. GLPoints1->Static = !CBAnimate->Checked;
  86. GLPoints2->Static = !CBAnimate->Checked;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TForm1::CBPointParamsClick(TObject *Sender)
  90. {
  91. GLPoints1->PointParameters->Enabled = CBPointParams->Checked;
  92. GLPoints2->PointParameters->Enabled = CBPointParams->Checked;
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  96. {
  97. LabelFPS->Caption = Format("%.1f FPS",
  98. ARRAYOFCONST ((GLSceneViewer1->FramesPerSecond())));
  99. GLSceneViewer1->ResetPerformanceMonitor();
  100. }
  101. //---------------------------------------------------------------------------