fColumnD.pas 2.3 KB

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