fHierarchy.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. unit fHierarchy;
  2. interface
  3. uses
  4. System.Classes,
  5. System.SysUtils,
  6. System.Math,
  7. Vcl.Forms,
  8. Vcl.ComCtrls,
  9. Vcl.ExtCtrls,
  10. Vcl.StdCtrls,
  11. Vcl.Controls,
  12. GLS.Scene,
  13. GLS.Objects,
  14. GLS.Cadencer,
  15. GLS.AsyncTimer,
  16. GLS.SceneViewer,
  17. GLS.Coordinates,
  18. GLS.BaseClasses;
  19. type
  20. TFormHierarchy = class(TForm)
  21. GLScene1: TGLScene;
  22. GLSceneViewer1: TGLSceneViewer;
  23. TrackBar: TTrackBar;
  24. Cube1: TGLCube;
  25. Cube3: TGLCube;
  26. Cube2: TGLCube;
  27. GLCamera1: TGLCamera;
  28. GLLightSource1: TGLLightSource;
  29. CBPlay: TCheckBox;
  30. DummyCube1: TGLDummyCube;
  31. DummyCube2: TGLDummyCube;
  32. GLCadencer1: TGLCadencer;
  33. procedure TrackBarChange(Sender: TObject);
  34. procedure FormResize(Sender: TObject);
  35. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  36. procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
  37. newTime: Double);
  38. private
  39. { Private declarations }
  40. public
  41. end;
  42. var
  43. FormHierarchy: TFormHierarchy;
  44. implementation
  45. {$R *.DFM}
  46. procedure TFormHierarchy.TrackBarChange(Sender: TObject);
  47. var
  48. t : Integer;
  49. begin
  50. t:=TrackBar.Position;
  51. // the "sun" spins slowly
  52. Cube1.TurnAngle:=t/4;
  53. // "earth" rotates around the sun and spins
  54. DummyCube1.TurnAngle:=-t;
  55. Cube2.TurnAngle:=t*2;
  56. // "moon" rotates around earth and spins
  57. DummyCube2.RollAngle:=3*t;
  58. Cube3.TurnAngle:=4*t;
  59. end;
  60. procedure TFormHierarchy.GLCadencer1Progress(Sender: TObject; const deltaTime,
  61. newTime: Double);
  62. begin
  63. if CBPlay.Checked and Visible then begin
  64. // simulate a user action on the trackbar...
  65. TrackBar.Position:=((TrackBar.Position+1) mod 360);
  66. end;
  67. end;
  68. procedure TFormHierarchy.FormResize(Sender: TObject);
  69. begin
  70. GLSceneViewer1.ResetPerformanceMonitor;
  71. end;
  72. procedure TFormHierarchy.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  73. begin
  74. // We need to stop playing here :
  75. // since the timer is asynchronous, if we don't stop play,
  76. // it may get triggered during the form's destruction
  77. CBPlay.Checked:=False;
  78. end;
  79. end.