Unit1.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.h"
  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.SkyDome"
  14. #pragma link "GLS.GeomObjects"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma link "GLS.Imposter"
  17. #pragma resource "*.dfm"
  18. TForm1 *Form1;
  19. TGLRenderPoint *renderPoint;
  20. //TGLStaticImposterBuilder impBuilder;
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm1::TForm1(TComponent* Owner)
  23. : TForm(Owner)
  24. {
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::FormCreate(TObject *Sender)
  28. {
  29. renderPoint = (TGLRenderPoint *) GLDummyCube1->AddNewChild(__classid(TGLRenderPoint));
  30. /* to do
  31. impBuilder = TGLStaticImposterBuilder.Create(Self);
  32. impBuilder->SampleSize = 64;
  33. impBuilder->SamplingRatioBias = 1.3;
  34. impBuilder->Coronas->Items[0].Samples = 32;
  35. impBuilder->Coronas->Add(15, 24);
  36. impBuilder->Coronas->Add(30, 24);
  37. impBuilder->Coronas->Add(45, 16);
  38. impBuilder->Coronas->Add(60, 16);
  39. impBuilder->Coronas->Add(85, 16);
  40. impBuilder->RenderPoint = renderPoint;
  41. impBuilder->RequestImposterFor(GLTeapot1);
  42. */
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  46. const double newTime)
  47. {
  48. GLSceneViewer1->Invalidate();
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  52. {
  53. LabelFPS->Caption = GLSceneViewer1->FramesPerSecondText();
  54. if (CBShowImposter->Checked)
  55. LabelFPS->Caption = LabelFPS->Caption +" - 3721 imposters";
  56. /*
  57. LabelTexSize->Caption = Format("%d x %d - %.1f%%",
  58. ARRAYOFCONST((impBuilder->TextureSize->X, impBuilder->TextureSize->Y,
  59. impBuilder->TextureFillRatio*100)));
  60. */
  61. GLSceneViewer1->ResetPerformanceMonitor();
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::CBShowTeapotClick(TObject *Sender)
  65. {
  66. GLTeapot1->Visible = CBShowTeapot->Checked;
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::CBShowImposterClick(TObject *Sender)
  70. {
  71. GLDirectOpenGL1->Visible = CBShowImposter->Checked;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  75. int X, int Y)
  76. {
  77. if (Shift.Contains(ssLeft))
  78. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  79. else if (Shift.Contains(ssRight))
  80. GLCamera1->RotateTarget(my - Y, mx - X, 0);
  81. mx = X;
  82. my = Y;
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TForm1::GLDirectOpenGL1Render(TObject *Sender, TGLRenderContextInfo &rci)
  86. {
  87. int x, y;
  88. Gls::Vectorgeometry::TVector camPos;
  89. Gls::Vectorgeometry::TVector pos;
  90. /* to do
  91. TImposter *imp;
  92. imp = impBuilder->ImposterFor(GLTeapot1);
  93. if ((imp=nil) or (imp->Texture->Handle=0)) Exit;
  94. imp->BeginRender(rci);
  95. for (x=-30; x<30; x++) do
  96. for (y=-30;y<30; y++) do {
  97. MakePoint(pos, x*5, 0, y*4);
  98. camPos = VectorSubtract(rci->cameraPosition, pos);
  99. imp->Render(rci, pos, camPos, 1);
  100. }
  101. imp->EndRender(rci);
  102. */
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  106. TShiftState Shift, int X, int Y)
  107. {
  108. mx = X;
  109. my = Y;
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  113. TPoint &MousePos, bool &Handled)
  114. {
  115. GLCamera1->
  116. AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TForm1::FormResize(TObject *Sender)
  120. {
  121. if(GLSceneViewer1->Width > GLSceneViewer1->Height)
  122. GLCamera1->SceneScale = (float)GLSceneViewer1->Height / 300;
  123. else
  124. GLCamera1->SceneScale = (float)GLSceneViewer1->Width / 360;
  125. }
  126. //---------------------------------------------------------------------------