fPoints.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. unit fPoints;
  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. GLS.VectorTypes,
  16. GLS.Objects,
  17. GLS.SceneViewer,
  18. GLS.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;
  41. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  42. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  43. X, Y: Integer);
  44. procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
  45. 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
  52. end;
  53. var
  54. FormPoints: TFormPoints;
  55. implementation
  56. {$R *.DFM}
  57. const
  58. cNbPoints = 180;
  59. procedure TFormPoints.FormCreate(Sender: TObject);
  60. begin
  61. // allocate points in the 1st point set
  62. GLPoints1.Positions.Count:=cNbPoints;
  63. // specify white color for the 1st point set
  64. // (if a single color is defined, all points will use it,
  65. // otherwise, it's a per-point coloring)
  66. GLPoints1.Colors.Add(clrWhite);
  67. // specify blue color for the 2nd point set
  68. GLPoints2.Colors.Add(clrBlue);
  69. end;
  70. procedure TFormPoints.GLCadencer1Progress(Sender: TObject; const deltaTime,
  71. newTime: Double);
  72. var
  73. i : Integer;
  74. f, a, ab, ca, sa : Single;
  75. p : TAffineVectorList;
  76. v : TAffineVector;
  77. begin
  78. if CBAnimate.Checked then 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 begin
  107. GLCamera1.MoveAroundTarget(my-y, mx-x);
  108. mx:=x;
  109. my:=y;
  110. end;
  111. end;
  112. procedure TFormPoints.CBAnimateClick(Sender: TObject);
  113. begin
  114. GLPoints1.Static:=not CBAnimate.Checked;
  115. GLPoints2.Static:=not CBAnimate.Checked;
  116. end;
  117. procedure TFormPoints.CBPointParamsClick(Sender: TObject);
  118. begin
  119. GLPoints1.PointParameters.Enabled:=CBPointParams.Checked;
  120. GLPoints2.PointParameters.Enabled:=CBPointParams.Checked;
  121. end;
  122. procedure TFormPoints.Timer1Timer(Sender: TObject);
  123. begin
  124. LabelFPS.Caption:=Format('%.1f FPS', [GLSceneViewer1.FramesPerSecond]);
  125. GLSceneViewer1.ResetPerformanceMonitor;
  126. end;
  127. end.