fMegaCube.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. unit fMegaCube;
  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.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;
  33. const deltaTime, newTime: Double);
  34. private
  35. end;
  36. var
  37. FormMegacube: TFormMegacube;
  38. implementation
  39. {$R *.DFM}
  40. const
  41. cSize = 10;
  42. procedure TFormMegacube.FormCreate(Sender: TObject);
  43. var
  44. x, y, z: Integer;
  45. cube: TGLCube;
  46. factor, cubeSize: Single;
  47. begin
  48. // bench only creation and 1st render (with lists builds, etc...)
  49. factor := 70 / (cSize * 2 + 1);
  50. cubeSize := 0.4 * factor;
  51. for x := -cSize to cSize do
  52. for y := -cSize to cSize do
  53. for z := -cSize to cSize do
  54. begin
  55. cube := TGLCube(DummyCube1.AddNewChild(TGLCube));
  56. cube.Position.AsVector := PointMake(factor * x, factor * y, factor * z);
  57. cube.CubeWidth := cubeSize;
  58. cube.CubeHeight := cubeSize;
  59. cube.CubeDepth := cubeSize;
  60. with cube.Material.FrontProperties do
  61. begin
  62. Diffuse.Color := VectorLerp(clrYellow, clrRed, (x * x + y * y + z * z)
  63. / (cSize * cSize * 3));
  64. // uncomment following lines to stress OpenGL with more color changes calls
  65. Ambient.Color:=VectorLerp(clrYellow, clrRed, (x*x+y*y+z*z)/(cSize*cSize*3));
  66. Emission.Color:=VectorLerp(clrYellow, clrRed, (x*x+y*y+z*z)/(cSize*cSize*3));
  67. Specular.Color:=VectorLerp(clrYellow, clrRed, (x*x+y*y+z*z)/(cSize*cSize*3));
  68. end;
  69. end;
  70. end;
  71. procedure TFormMegacube.GLCadencer1Progress(Sender: TObject;
  72. const deltaTime, newTime: Double);
  73. begin
  74. DummyCube1.TurnAngle := 90 * newTime; // 90° per second
  75. end;
  76. end.