Unit1.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. #include "Math.hpp"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma resource "*.dfm"
  15. TForm1 *Form1;
  16. const int
  17. cNbPlanes = 30;
  18. const int
  19. cStackHeight = 8;
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::FormCreate(TObject *Sender)
  27. {
  28. int i;
  29. TGLPlane *plane;
  30. // our column is just a stack of planes
  31. for (i=0; i < cNbPlanes-1; i++)
  32. {
  33. // create planes as child of the dummycube
  34. plane = (TGLPlane *)(DummyCube1->AddNewChild(__classid (TGLPlane)));
  35. // default plane size is 1x1, we want bigger planes !
  36. plane->Width = 2;
  37. plane->Height = 2;
  38. // orient and position then planes in the stack
  39. plane->Position->Y = cStackHeight*(0.5-(float)i/cNbPlanes);
  40. plane->Direction->AsVector = YHmgVector;
  41. // we use the emission color, since there is no light in the scene
  42. // (allows 50+ FPS with software opengl on <400 Mhz CPUs ;)
  43. plane->Material->FrontProperties->Emission->Color = VectorLerp(clrBlue, clrYellow, i/cNbPlanes);
  44. }
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  48. const double newTime)
  49. {
  50. int i;
  51. // for all planes (all childs of the dummycube)
  52. for (i=0; i < DummyCube1->Count-1; i++)
  53. // roll them accordingly to our time reference and position in the stack
  54. DummyCube1->Children[i]->RollAngle = 90*cos(newTime+i*M_PI/cNbPlanes);
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  58. {
  59. // update FPS and reset counter for the next second
  60. StaticText1->Caption = Format("%.1f FPS",
  61. ARRAYOFCONST ((GLSceneViewer1->FramesPerSecond())));
  62. GLSceneViewer1->ResetPerformanceMonitor();
  63. }
  64. //---------------------------------------------------------------------------