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