fMainD.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. unit fMainD;
  2. interface
  3. uses
  4. System.Classes,
  5. System.SysUtils,
  6. System.Math,
  7. Vcl.Forms,
  8. Vcl.Graphics,
  9. Vcl.Controls,
  10. Vcl.ComCtrls,
  11. Vcl.ExtCtrls,
  12. Vcl.StdCtrls,
  13. GLS.Scene,
  14. GLS.Objects,
  15. GLS.AsyncTimer,
  16. GLS.Cadencer,
  17. GLS.AVIRecorder,
  18. GLS.SceneViewer,
  19. GLS.Coordinates,
  20. GLS.BaseClasses;
  21. type
  22. TForm1 = class(TForm)
  23. GLScene1: TGLScene;
  24. GLSceneViewer1: TGLSceneViewer;
  25. TrackBar: TTrackBar;
  26. Cube1: TGLCube;
  27. Cube3: TGLCube;
  28. Cube2: TGLCube;
  29. GLCamera1: TGLCamera;
  30. GLLightSource1: TGLLightSource;
  31. StaticText1: TStaticText;
  32. DummyCube1: TGLDummyCube;
  33. DummyCube2: TGLDummyCube;
  34. GLCadencer1: TGLCadencer;
  35. Button1: TButton;
  36. AVIRecorder1: TGLAVIRecorder;
  37. procedure TrackBarChange(Sender: TObject);
  38. procedure FormResize(Sender: TObject);
  39. procedure Button1Click(Sender: TObject);
  40. procedure FormKeyPress(Sender: TObject; var Key: Char);
  41. procedure AVIRecorder1PostProcessEvent(Sender: TObject;
  42. frame: TBitmap);
  43. private
  44. UserAbort : boolean;
  45. end;
  46. var
  47. Form1: TForm1;
  48. //-------------------------------------
  49. implementation
  50. {$R *.DFM}
  51. procedure TForm1.TrackBarChange(Sender: TObject);
  52. var
  53. t : Integer;
  54. begin
  55. t:=TrackBar.Position;
  56. // the "sun" spins slowly
  57. Cube1.TurnAngle:=t/4;
  58. // "earth" rotates around the sun and spins
  59. DummyCube1.TurnAngle:=-t;
  60. Cube2.TurnAngle:=t*2;
  61. // "moon" rotates around earth and spins
  62. DummyCube2.RollAngle:=3*t;
  63. Cube3.TurnAngle:=4*t;
  64. // update FPS count
  65. StaticText1.Caption:=IntToStr(Trunc(GLSceneViewer1.FramesPerSecond))+' FPS';
  66. end;
  67. procedure TForm1.FormResize(Sender: TObject);
  68. begin
  69. GLSceneViewer1.ResetPerformanceMonitor;
  70. AVIRecorder1.Width:=GLSceneViewer1.Width;
  71. AVIRecorder1.Height:=GLSceneViewer1.Height;
  72. end;
  73. procedure TForm1.Button1Click(Sender: TObject);
  74. var i : integer;
  75. SavedCap : string;
  76. begin
  77. if not AVIRecorder1.CreateAVIFile then Exit;
  78. // if AVIRecorder1.filename is empty, a dialog box will appear asking
  79. // for the filename. CreateAVIFile() will return a bool
  80. // indicating if user presses "cancel" in the dialog box.
  81. SavedCap:=caption;
  82. caption:='Press ESC to abort';
  83. UserAbort:=false;
  84. StaticText1.Visible:=false; // the FPS shown is not correct now,
  85. // so just hide it for the time being.
  86. i:=0;
  87. Button1.enabled:=false;
  88. TrackBar.enabled:=false;
  89. try
  90. while (i<360) and not UserAbort do begin
  91. TrackBar.Position:=i;
  92. TrackBarChange(self);
  93. AVIRecorder1.AddAVIFrame;
  94. // you might want to update your progress bar here.
  95. Application.ProcessMessages; // so that our app. is not freezed,
  96. // and will accept user abort.
  97. inc(i);
  98. end;
  99. finally
  100. AVIRecorder1.CloseAVIFile(UserAbort); // if UserAbort, CloseAVIFile will
  101. // also delete the unfinished file.
  102. caption:=SavedCap;
  103. StaticText1.Visible:=true;
  104. Button1.enabled:=true;
  105. TrackBar.enabled:=true;
  106. end;
  107. end;
  108. procedure TForm1.AVIRecorder1PostProcessEvent(Sender: TObject;
  109. frame: TBitmap);
  110. begin
  111. // PostProcess event is used to add a "watermark"
  112. // that will be in the AVI, but isn't visible on-screen
  113. with frame.Canvas do
  114. begin
  115. Font.Color:=clAqua;
  116. Font.Name:='Courrier New';
  117. Font.Size:=24;
  118. Font.Style:=[fsBold];
  119. Brush.Style:=bsClear;
  120. TextOut(20, 20, Format('GLScene %.3d', [TrackBar.Position]));
  121. end;
  122. end;
  123. procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
  124. begin
  125. UserAbort:=key=#27;
  126. end;
  127. end.