fMegaGlassCube.pas 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. unit fMegaGlassCube;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. Vcl.Graphics,
  8. Vcl.Controls,
  9. Vcl.Forms,
  10. Vcl.ExtCtrls,
  11. GLS.Scene,
  12. GLS.Objects,
  13. GLS.VectorGeometry,
  14. GLS.Texture,
  15. GLS.Cadencer,
  16. GLS.VectorTypes,
  17. GLS.SceneViewer,
  18. GLS.Color,
  19. GLS.Coordinates,
  20. GLS.Material,
  21. GLS.SimpleNavigation,
  22. GLS.BaseClasses;
  23. type
  24. TFormMegaglasscube = class(TForm)
  25. GLSceneViewer1: TGLSceneViewer;
  26. GLScene1: TGLScene;
  27. GLCamera1: TGLCamera;
  28. DummyCube1: TGLDummyCube;
  29. GLLightSource1: TGLLightSource;
  30. GLCadencer1: TGLCadencer;
  31. GLSimpleNavigation1: TGLSimpleNavigation;
  32. procedure FormCreate(Sender: TObject);
  33. procedure GLCadencer1Progress(Sender: TObject;
  34. const deltaTime, newTime: Double);
  35. private
  36. public
  37. end;
  38. var
  39. FormMegaglasscube: TFormMegaglasscube;
  40. implementation
  41. {$R *.DFM}
  42. const
  43. cSize = 5;
  44. procedure TFormMegaglasscube.FormCreate(Sender: TObject);
  45. var
  46. x, y, z : Integer;
  47. cube : TGLCube;
  48. factor, cubeSize : Single;
  49. Color : TColor;
  50. begin
  51. // bench only creation and 1st render (with lists builds, etc...)
  52. factor:=70/(cSize*2+1);
  53. cubeSize:=0.4*factor;
  54. for x := -cSize to cSize do
  55. for y := -cSize to cSize do
  56. for z := -cSize to cSize do
  57. begin
  58. cube := TGLCube(DummyCube1.AddNewChild(TGLCube));
  59. cube.Position.AsVector := PointMake(factor * x, factor * y, factor * z);
  60. cube.CubeWidth := cubeSize;
  61. cube.CubeHeight := cubeSize;
  62. cube.CubeDepth := cubeSize;
  63. cube.Material.BlendingMode := bmTransparency;
  64. with cube.Material.FrontProperties do
  65. begin
  66. Color := Random(1);
  67. Diffuse.Color := VectorLerp(clrBlue, clrWhite, (x * x + y * y + z * z)
  68. / (cSize * cSize * 3));
  69. Diffuse.Alpha := 0.5;
  70. end;
  71. end;
  72. end;
  73. procedure TFormMegaglasscube.GLCadencer1Progress(Sender: TObject; const deltaTime,
  74. newTime: Double);
  75. begin
  76. DummyCube1.TurnAngle:=90*newTime; // 90° per second
  77. end;
  78. end.