fMirror.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. unit fMirror;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Classes,
  6. Vcl.Graphics,
  7. Vcl.Controls,
  8. Vcl.Forms,
  9. Vcl.ExtCtrls,
  10. Vcl.StdCtrls,
  11. GLS.BaseClasses,
  12. GLS.Scene,
  13. GLS.Objects,
  14. GLS.Extrusion,
  15. GLS.Mirror,
  16. GLS.Cadencer,
  17. GLS.SceneViewer,
  18. GLS.GeomObjects,
  19. GLS.Coordinates,
  20. GLS.MultiPolygon;
  21. type
  22. TFormMirror = class(TForm)
  23. GLSceneViewer1: TGLSceneViewer;
  24. GLScene1: TGLScene;
  25. GLCamera1: TGLCamera;
  26. GLLightSource1: TGLLightSource;
  27. Sphere: TGLSphere;
  28. ReflectingObjects: TGLDummyCube;
  29. Cylinder: TGLTorus;
  30. Teapot1: TGLTeapot;
  31. Cylinder1: TGLCylinder;
  32. GLMirror: TGLMirror;
  33. Cadre: TGLExtrusionSolid;
  34. Timer1: TTimer;
  35. GLCadencer1: TGLCadencer;
  36. Panel1: TPanel;
  37. LabelFPS: TLabel;
  38. CBOpaque: TCheckBox;
  39. CBStencil: TCheckBox;
  40. Cylinder2: TGLCylinder;
  41. CBClearZ: TCheckBox;
  42. CylinderThroughMirror: TGLCylinder;
  43. CBPlaneClip: TCheckBox;
  44. DCNonReflectingStuff: TGLDummyCube;
  45. procedure GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
  46. Shift: TShiftState; X, Y: Integer);
  47. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  48. X, Y: Integer);
  49. procedure Timer1Timer(Sender: TObject);
  50. procedure GLCadencer1Progress(Sender: TObject;
  51. const deltaTime, newTime: Double);
  52. procedure CBOpaqueClick(Sender: TObject);
  53. procedure CBStencilClick(Sender: TObject);
  54. procedure FormResize(Sender: TObject);
  55. procedure CBClearZClick(Sender: TObject);
  56. procedure CBPlaneClipClick(Sender: TObject);
  57. procedure FormCreate(Sender: TObject);
  58. private
  59. public
  60. mx, my: Integer;
  61. end;
  62. var
  63. FormMirror: TFormMirror;
  64. implementation
  65. {$R *.DFM}
  66. procedure TFormMirror.FormCreate(Sender: TObject);
  67. begin
  68. CBClearZClick(Self);
  69. CBOpaqueClick(Self);
  70. end;
  71. //
  72. // Those events simply add/remove one of the mirror options
  73. // when the related checkbox is clicked
  74. //
  75. procedure TFormMirror.CBOpaqueClick(Sender: TObject);
  76. begin
  77. if CBOpaque.Checked then
  78. GLMirror.MirrorOptions := GLMirror.MirrorOptions + [moOpaque]
  79. else
  80. GLMirror.MirrorOptions := GLMirror.MirrorOptions - [moOpaque];
  81. end;
  82. procedure TFormMirror.CBStencilClick(Sender: TObject);
  83. begin
  84. if CBStencil.Checked then
  85. GLMirror.MirrorOptions := GLMirror.MirrorOptions + [moUseStencil]
  86. else
  87. GLMirror.MirrorOptions := GLMirror.MirrorOptions - [moUseStencil];
  88. end;
  89. procedure TFormMirror.CBClearZClick(Sender: TObject);
  90. begin
  91. if CBClearZ.Checked then
  92. GLMirror.MirrorOptions := GLMirror.MirrorOptions + [moClearZBuffer]
  93. else
  94. GLMirror.MirrorOptions := GLMirror.MirrorOptions - [moClearZBuffer];
  95. end;
  96. procedure TFormMirror.CBPlaneClipClick(Sender: TObject);
  97. begin
  98. if CBPlaneClip.Checked then
  99. GLMirror.MirrorOptions := GLMirror.MirrorOptions + [moMirrorPlaneClip]
  100. else
  101. GLMirror.MirrorOptions := GLMirror.MirrorOptions - [moMirrorPlaneClip];
  102. end;
  103. //
  104. // Standard-issue move around target code
  105. //
  106. procedure TFormMirror.GLSceneViewer1MouseDown(Sender: TObject; Button: TMouseButton;
  107. Shift: TShiftState; X, Y: Integer);
  108. begin
  109. mx := X;
  110. my := Y;
  111. end;
  112. procedure TFormMirror.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  113. X, Y: Integer);
  114. begin
  115. if Shift <> [] then
  116. begin
  117. GLCamera1.MoveAroundTarget(my - Y, mx - X);
  118. mx := X;
  119. my := Y;
  120. end;
  121. end;
  122. //
  123. // Standard issue resize/zoom, timer and viewr invalidation (to force redraws)
  124. //
  125. procedure TFormMirror.FormResize(Sender: TObject);
  126. begin
  127. GLCamera1.SceneScale := GLSceneViewer1.Width / 380;
  128. end;
  129. procedure TFormMirror.Timer1Timer(Sender: TObject);
  130. begin
  131. LabelFPS.Caption := Format('%.1f FPS', [GLSceneViewer1.FramesPerSecond]);
  132. GLSceneViewer1.ResetPerformanceMonitor;
  133. end;
  134. procedure TFormMirror.GLCadencer1Progress(Sender: TObject;
  135. const deltaTime, newTime: Double);
  136. begin
  137. GLSceneViewer1.Invalidate;
  138. end;
  139. end.