fColumn.pas 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. unit fColumn;
  2. interface
  3. uses
  4. System.Classes,
  5. System.SysUtils,
  6. Vcl.Forms,
  7. Vcl.Controls,
  8. Vcl.ExtCtrls,
  9. Vcl.StdCtrls,
  10. GLS.Scene,
  11. GLS.PersistentClasses,
  12. GLS.Objects,
  13. GLS.Texture,
  14. GLS.VectorTypes,
  15. GLS.Cadencer,
  16. GLS.SceneViewer,
  17. GLS.Color,
  18. GLS.Coordinates,
  19. GLS.BaseClasses,
  20. GLS.VectorGeometry;
  21. type
  22. TFormColumn = class(TForm)
  23. GLScene1: TGLScene;
  24. GLSceneViewer1: TGLSceneViewer;
  25. GLCamera1: TGLCamera;
  26. DummyCube1: TGLDummyCube;
  27. StaticText1: TStaticText;
  28. Timer1: TTimer;
  29. GLCadencer1: TGLCadencer;
  30. procedure FormCreate(Sender: TObject);
  31. procedure Timer1Timer(Sender: TObject);
  32. procedure GLCadencer1Progress(Sender: TObject;
  33. const deltaTime, newTime: Double);
  34. end;
  35. var
  36. FormColumn: TFormColumn;
  37. implementation
  38. {$R *.DFM}
  39. const
  40. cNbPlanes = 30;
  41. cStackHeight = 8;
  42. procedure TFormColumn.FormCreate(Sender: TObject);
  43. var
  44. i: Integer;
  45. plane: TGLPlane;
  46. begin
  47. // our column is just a stack of planes
  48. for i := 0 to cNbPlanes - 1 do
  49. begin
  50. // create planes as child of the dummycube
  51. plane := TGLPlane(DummyCube1.AddNewChild(TGLPlane));
  52. // default plane size is 1x1, we want bigger planes !
  53. plane.Width := 2;
  54. plane.Height := 2;
  55. // orient and position then planes in the stack
  56. plane.Position.Y := cStackHeight * (0.5 - i / cNbPlanes);
  57. plane.Direction.AsVector := YHmgVector;
  58. // we use the emission color, since there is no light in the scene
  59. // (allows 50+ FPS with software opengl on <400 Mhz CPUs ;)
  60. plane.Material.FrontProperties.Emission.Color :=
  61. VectorLerp(clrBlue, clrYellow, i / cNbPlanes);
  62. end;
  63. end;
  64. procedure TFormColumn.GLCadencer1Progress(Sender: TObject;
  65. const deltaTime, newTime: Double);
  66. var
  67. i: Integer;
  68. begin
  69. // for all planes (all childs of the dummycube)
  70. for i := 0 to DummyCube1.Count - 1 do
  71. // roll them accordingly to our time reference and position in the stack
  72. (DummyCube1.Children[i] as TGLPlane).RollAngle :=
  73. 90 * cos(newTime + i * PI / cNbPlanes);
  74. end;
  75. procedure TFormColumn.Timer1Timer(Sender: TObject);
  76. begin
  77. // update FPS and reset counter for the next second
  78. StaticText1.Caption := Format('%.1f FPS', [GLSceneViewer1.FramesPerSecond]);
  79. GLSceneViewer1.ResetPerformanceMonitor;
  80. end;
  81. end.