fTentaclesD.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. unit fTentaclesD;
  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.PersistentClasses,
  13. GLS.Objects,
  14. GLS.Extrusion,
  15. GLS.Cadencer,
  16. Stage.VectorGeometry,
  17. Stage.VectorTypes,
  18. GLS.Texture,
  19. GLS.SceneViewer,
  20. GLS.Color,
  21. GLS.Coordinates,
  22. GLS.BaseClasses;
  23. type
  24. TFormTentacles = class(TForm)
  25. GLScene1: TGLScene;
  26. GLSceneViewer1: TGLSceneViewer;
  27. GLCamera1: TGLCamera;
  28. DCBase: TGLDummyCube;
  29. GLLightSource1: TGLLightSource;
  30. GLCadencer1: TGLCadencer;
  31. DCTarget: TGLDummyCube;
  32. Timer1: TTimer;
  33. Pipe1: TGLPipe;
  34. Pipe2: TGLPipe;
  35. Pipe3: TGLPipe;
  36. Pipe4: TGLPipe;
  37. Pipe5: TGLPipe;
  38. Sphere1: TGLSphere;
  39. PanelFPS: TPanel;
  40. procedure GLCadencer1Progress(Sender: TObject;
  41. const deltaTime, newTime: Double);
  42. procedure FormCreate(Sender: TObject);
  43. procedure Timer1Timer(Sender: TObject);
  44. private
  45. public
  46. end;
  47. var
  48. FormTentacles: TFormTentacles;
  49. implementation
  50. {$R *.dfm}
  51. const
  52. cNbNodes = 32;
  53. procedure TFormTentacles.FormCreate(Sender: TObject);
  54. var
  55. i, k: Integer;
  56. pipe: TGLPipe;
  57. begin
  58. // prepare the TGLPipe objects (add node, set props...)
  59. for k := 0 to DCBase.Count - 1 do
  60. if (DCBase.Children[k] is TGLPipe) then
  61. begin
  62. pipe := TGLPipe(DCBase.Children[k]);
  63. pipe.Nodes.Clear;
  64. for i := 1 to cNbNodes do
  65. pipe.Nodes.AddNode(0, i / 8, 0);
  66. pipe.Radius := 0.1;
  67. // enable per-node coloring in the TGLPipe
  68. pipe.NodesColorMode := pncmDiffuse;
  69. // divisions between nodes (for spline interpolation)
  70. pipe.Division := 3;
  71. // No geometry compilation/cacheing, render directly
  72. // (geometry changes completely from frame to frame)
  73. pipe.ObjectStyle := pipe.ObjectStyle + [osDirectDraw];
  74. end;
  75. end;
  76. procedure TFormTentacles.GLCadencer1Progress(Sender: TObject;
  77. const deltaTime, newTime: Double);
  78. var
  79. i, k: Integer;
  80. t, t1, t2, r: Double;
  81. pipe: TGLPipe;
  82. begin
  83. t := newTime;
  84. for k := 0 to DCBase.Count - 1 do
  85. if (DCBase.Children[k] is TGLPipe) then
  86. begin
  87. pipe := TGLPipe(DCBase.Children[k]);
  88. with pipe.Nodes do
  89. begin
  90. BeginUpdate;
  91. for i := 0 to Count - 1 do
  92. with (Items[i] as TGLPipeNode) do
  93. begin
  94. // don't search any hidden logic behind the formulaes below:
  95. // they're just here to induce this sickening weirdo movement
  96. t1 := -t + i * 0.1 + k * c2PI / 5;
  97. r := (Sin(3 * t + k) + 2) * 0.5 * ((2 * i + Count) / Count);
  98. X := Cos(t1) * r;
  99. Z := Sin(t1) * r;
  100. t2 := 2 * (t + i / (Count - 1) + k);
  101. Color.Color := VectorLerp(clrSeaGreen, clrYellow, Sin(t2));
  102. RadiusFactor := (1 + (Sin(t2) * 0.5)) * ln((Count - i)) * 0.5;
  103. end;
  104. EndUpdate;
  105. end;
  106. end;
  107. Sphere1.Radius := 1.1 + Sin(2 * t) * 0.1;
  108. end;
  109. procedure TFormTentacles.Timer1Timer(Sender: TObject);
  110. begin
  111. // standard FPS counter
  112. PanelFPS.Caption := Format('%.1f FPS', [GLSceneViewer1.FramesPerSecond]);
  113. GLSceneViewer1.ResetPerformanceMonitor;
  114. end;
  115. end.