fPointsD.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. unit fPointsD;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. System.Math,
  8. Vcl.Graphics,
  9. Vcl.Controls,
  10. Vcl.Forms,
  11. Vcl.Dialogs,
  12. Vcl.StdCtrls,
  13. Vcl.ExtCtrls,
  14. GLS.Scene,
  15. GLScene.VectorTypes,
  16. GLS.Objects,
  17. GLS.SceneViewer,
  18. GLScene.VectorGeometry,
  19. GLS.VectorLists,
  20. GLS.Cadencer,
  21. GLS.Texture,
  22. GLS.Color,
  23. GLS.Coordinates,
  24. GLS.BaseClasses;
  25. type
  26. TFormPoints = class(TForm)
  27. GLScene1: TGLScene;
  28. GLSceneViewer1: TGLSceneViewer;
  29. GLCamera1: TGLCamera;
  30. DummyCube1: TGLDummyCube;
  31. GLPoints1: TGLPoints;
  32. GLCadencer1: TGLCadencer;
  33. GLPoints2: TGLPoints;
  34. Panel1: TPanel;
  35. CBPointParams: TCheckBox;
  36. CBAnimate: TCheckBox;
  37. Timer1: TTimer;
  38. LabelFPS: TLabel;
  39. procedure FormCreate(Sender: TObject);
  40. procedure GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
  41. Shift: TShiftState; X, Y: Integer);
  42. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  43. X, Y: Integer);
  44. procedure GLCadencer1Progress(Sender: TObject;
  45. const deltaTime, newTime: Double);
  46. procedure CBAnimateClick(Sender: TObject);
  47. procedure CBPointParamsClick(Sender: TObject);
  48. procedure Timer1Timer(Sender: TObject);
  49. private
  50. public
  51. mx, my: Integer end;
  52. var
  53. FormPoints: TFormPoints;
  54. implementation
  55. {$R *.DFM}
  56. const
  57. cNbPoints = 180;
  58. procedure TFormPoints.FormCreate(Sender: TObject);
  59. begin
  60. // allocate points in the 1st point set
  61. GLPoints1.Positions.Count := cNbPoints;
  62. // specify white color for the 1st point set
  63. // (if a single color is defined, all points will use it,
  64. // otherwise, it's a per-point coloring)
  65. GLPoints1.Colors.Add(clrWhite);
  66. // specify blue color for the 2nd point set
  67. GLPoints2.Colors.Add(clrGold);
  68. end;
  69. procedure TFormPoints.GLCadencer1Progress(Sender: TObject;
  70. const deltaTime, newTime: Double);
  71. var
  72. i: Integer;
  73. f, a, ab, ca, sa: Single;
  74. p: TGLAffineVectorList;
  75. v: TAffineVector;
  76. begin
  77. if CBAnimate.Checked then
  78. begin
  79. // update the 1st point set with values from a math func
  80. f := 1 + Cos(newTime);
  81. p := GLPoints1.Positions;
  82. ab := newTime * 0.1;
  83. for i := 0 to cNbPoints - 1 do
  84. begin
  85. a := DegToRad(4 * i) + ab;
  86. SinCos(a, sa, ca);
  87. v.X := 2 * ca;
  88. v.Y := 2 * Cos(f * a);
  89. v.Z := 2 * sa;
  90. p.Create[i] := v;
  91. end;
  92. // replicate points in second set
  93. GLPoints2.Positions := GLPoints1.Positions;
  94. end;
  95. GLSceneViewer1.Invalidate;
  96. end;
  97. procedure TFormPoints.GLSceneViewer1MouseDown(Sender: TObject;
  98. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  99. begin
  100. mx := X;
  101. my := Y;
  102. end;
  103. procedure TFormPoints.GLSceneViewer1MouseMove(Sender: TObject;
  104. Shift: TShiftState; X, Y: Integer);
  105. begin
  106. if Shift <> [] then
  107. begin
  108. GLCamera1.MoveAroundTarget(my - Y, mx - X);
  109. mx := X;
  110. my := Y;
  111. end;
  112. end;
  113. procedure TFormPoints.CBAnimateClick(Sender: TObject);
  114. begin
  115. GLPoints1.Static := not CBAnimate.Checked;
  116. GLPoints2.Static := not CBAnimate.Checked;
  117. end;
  118. procedure TFormPoints.CBPointParamsClick(Sender: TObject);
  119. begin
  120. GLPoints1.PointParameters.Enabled := CBPointParams.Checked;
  121. GLPoints2.PointParameters.Enabled := CBPointParams.Checked;
  122. end;
  123. procedure TFormPoints.Timer1Timer(Sender: TObject);
  124. begin
  125. LabelFPS.Caption := Format('%.1f FPS', [GLSceneViewer1.FramesPerSecond]);
  126. GLSceneViewer1.ResetPerformanceMonitor;
  127. end;
  128. end.