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