Unit1.cpp 3.0 KB

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