fTentaclesC.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // ---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #include <System.Math.hpp>
  5. #pragma hdrstop
  6. #include "fTentaclesC.h"
  7. // ---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma link "GLS.BaseClasses"
  10. #pragma link "GLS.Cadencer"
  11. #pragma link "GLS.Coordinates"
  12. #pragma link "GLS.Extrusion"
  13. #pragma link "GLS.Objects"
  14. #pragma link "GLS.Scene"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma resource "*.dfm"
  17. TFormTentacles* FormTentacles;
  18. // ---------------------------------------------------------------------------
  19. __fastcall TFormTentacles::TFormTentacles(TComponent* Owner) : TForm(Owner) {}
  20. // ---------------------------------------------------------------------------
  21. const int cNbNodes = 32;
  22. void __fastcall TFormTentacles::FormCreate(TObject* Sender)
  23. {
  24. int i, k;
  25. TGLPipe* pipe;
  26. // prepare the TGLPipe objects (add node, set props...)
  27. for (k = 0; k < DCBase->Count - 1; k++) {
  28. if (dynamic_cast<TGLPipe*>(DCBase->Children[k])) {
  29. pipe = (TGLPipe*)(DCBase->Children[k]);
  30. pipe->Nodes->Clear();
  31. for (i = 0; i < cNbNodes - 1; i++)
  32. pipe->Nodes->AddNode(0, i / 8, 0);
  33. pipe->Radius = 0.1;
  34. // enable per-node coloring in the TGLPipe
  35. pipe->NodesColorMode = pncmDiffuse;
  36. // divisions between nodes (for spline interpolation)
  37. pipe->Division = 3;
  38. // No geometry compilation/cacheing, render directly
  39. // (geometry changes completely from frame to frame)
  40. pipe->ObjectStyle = pipe->ObjectStyle << osDirectDraw;
  41. }
  42. }
  43. }
  44. // ---------------------------------------------------------------------------
  45. void __fastcall TFormTentacles::GLCadencer1Progress(
  46. TObject* Sender, const double deltaTime, const double newTime)
  47. {
  48. int i, k;
  49. float t, t1, t2, r;
  50. TGLPipe* pipe;
  51. t = newTime;
  52. for (k = 0; k < DCBase->Count - 1; k++)
  53. if (dynamic_cast<TGLPipe*>(DCBase->Children[k])) {
  54. pipe = (TGLPipe*)(DCBase->Children[k]);
  55. pipe->Nodes->BeginUpdate();
  56. for (i = 0; i < pipe->Nodes->Count - 1; i++) {
  57. // don't search any hidden logic behind the formulaes below:
  58. // they're just here to induce this sickening weirdo movement
  59. t1 = -t + i * 0.1 + k * (2 * M_PI) / 5;
  60. r = (Sin(3 * t + k) + 2) * 0.5 * ((2 * i + pipe->Nodes->Count) / pipe->Nodes->Count);
  61. pipe->Nodes->Items[i]->X = Cos(t1) * r;
  62. pipe->Nodes->Items[i]->Z = Sin(t1) * r;
  63. t2 = 2 * (t + i / (pipe->Nodes->Count - 1) + k);
  64. pipe->Material->FrontProperties->Ambient->Color =
  65. VectorLerp(clrAqua, clrYellow, Sin(t2));
  66. pipe->Radius = (1 + (Sin(t2) * 0.5)) * Ln((pipe->Nodes->Count - i)) * 0.5;
  67. }
  68. pipe->Nodes->EndUpdate();
  69. }
  70. Sphere1->Radius = 1.4 + Sin(2 * t) * 0.1;
  71. }
  72. // ---------------------------------------------------------------------------
  73. void __fastcall TFormTentacles::Timer1Timer(TObject* Sender)
  74. {
  75. /*
  76. PanelFPS->Caption =
  77. Format("%.1f FPS", ARRAYOFCONST((GLSceneViewer1->FramesPerSecond())));
  78. */
  79. PanelFPS->Caption = GLSceneViewer1->FramesPerSecond();
  80. GLSceneViewer1->ResetPerformanceMonitor();
  81. }
  82. // ---------------------------------------------------------------------------