fPointsC.cpp 3.3 KB

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