2
0

fMegaCubeD.pas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. unit fMegaCubeD;
  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. GLScene.VectorGeometry,
  14. GLS.Texture,
  15. GLS.Cadencer,
  16. GLScene.VectorTypes,
  17. GLS.SceneViewer,
  18. GLS.Color,
  19. GLS.Coordinates,
  20. GLS.BaseClasses,
  21. GLS.SimpleNavigation;
  22. type
  23. TFormMegacube = class(TForm)
  24. GLSceneViewer1: TGLSceneViewer;
  25. GLScene1: TGLScene;
  26. GLCamera1: TGLCamera;
  27. DummyCube1: TGLDummyCube;
  28. GLLightSource1: TGLLightSource;
  29. GLCadencer1: TGLCadencer;
  30. GLSimpleNavigation1: TGLSimpleNavigation;
  31. procedure FormCreate(Sender: TObject);
  32. procedure GLCadencer1Progress(Sender: TObject; const deltaTime, newTime: Double);
  33. private
  34. end;
  35. var
  36. FormMegacube: TFormMegacube;
  37. implementation
  38. {$R *.DFM}
  39. const
  40. cSize = 10;
  41. procedure TFormMegacube.FormCreate(Sender: TObject);
  42. var
  43. x, y, z: Integer;
  44. cube: TGLCube;
  45. factor, cubeSize: Single;
  46. begin
  47. // bench only creation and 1st render (with lists builds, etc...)
  48. factor := 70 / (cSize * 2 + 1);
  49. cubeSize := 0.4 * factor;
  50. for x := -cSize to cSize do
  51. for y := -cSize to cSize do
  52. for z := -cSize to cSize do
  53. begin
  54. cube := TGLCube(DummyCube1.AddNewChild(TGLCube));
  55. cube.Position.AsVector := PointMake(factor * x, factor * y, factor * z);
  56. cube.CubeWidth := cubeSize;
  57. cube.CubeHeight := cubeSize;
  58. cube.CubeDepth := cubeSize;
  59. with cube.Material.FrontProperties do
  60. begin
  61. Diffuse.Color := VectorLerp(clrYellow, clrRed, (x * x + y * y + z * z) /
  62. (cSize * cSize * 3));
  63. // uncomment following lines to stress OpenGL with more color changes calls
  64. Ambient.Color := VectorLerp(clrYellow, clrRed, (x * x + y * y + z * z) /
  65. (cSize * cSize * 3));
  66. Emission.Color := VectorLerp(clrYellow, clrRed, (x * x + y * y + z * z) /
  67. (cSize * cSize * 3));
  68. Specular.Color := VectorLerp(clrYellow, clrRed, (x * x + y * y + z * z) /
  69. (cSize * cSize * 3));
  70. end;
  71. end;
  72. end;
  73. procedure TFormMegacube.GLCadencer1Progress(Sender: TObject; const deltaTime, newTime: Double);
  74. begin
  75. DummyCube1.TurnAngle := 90 * newTime; // 90° per second
  76. end;
  77. end.