fPanoViewerC.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #include <math.h>
  5. #pragma hdrstop
  6. #include "fPanoViewerC.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma link "GLS.Objects"
  10. #pragma link "GLS.Scene"
  11. #pragma link "GLS.Texture"
  12. #pragma link "GLS.SceneViewer"
  13. #pragma link "GLS.BaseClasses"
  14. #pragma link "GLS.Coordinates"
  15. #pragma link "GLS.Material"
  16. #pragma link "GLS.Keyboard"
  17. #pragma resource "*.dfm"
  18. TForm1* Form1;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}
  21. //---------------------------------------------------------------------------
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject* Sender)
  24. {
  25. Path = GetCurrentAssetPath(); // or Path = ExtractFilePath(ParamStr(0));
  26. SetCurrentDir(Path + "\\panorana"); // GetDir(0, Path);
  27. OpenPictureDialog1->InitialDir = Path + "\\panorama";
  28. OpenPictureDialog1->FileName = "sejourstmathieu2048.jpg";
  29. }
  30. void __fastcall TForm1::BtnLoadClick(TObject* Sender)
  31. {
  32. if (OpenPictureDialog1->Execute())
  33. GLMaterialLibrary1->Materials->Items[0]
  34. ->Material->Texture->Image->LoadFromFile(
  35. OpenPictureDialog1->FileName);
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TForm1::TrackBar1Change(TObject* Sender)
  39. {
  40. GLCamera1->FocalLength = TrackBar1->Position;
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::GLCadencer1Progress(
  44. TObject* Sender, const double deltaTime, const double newTime)
  45. {
  46. const int step_size = 20;
  47. float delta;
  48. float dx, dy;
  49. delta = step_size * 40 / GLCamera1->FocalLength * deltaTime;
  50. dx = 0;
  51. dy = 0;
  52. if (IsKeyDown(VK_LEFT))
  53. dx = dx + delta;
  54. if (IsKeyDown(VK_UP))
  55. dy = dy + delta;
  56. if (IsKeyDown(VK_RIGHT))
  57. dx = dx - delta;
  58. if (IsKeyDown(VK_DOWN))
  59. dy = dy - delta;
  60. PanCameraAround(dx, dy);
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::FormKeyDown(
  64. TObject* Sender, WORD &Key, TShiftState Shift)
  65. {
  66. Key = 0; // all keys handled by Form1
  67. }
  68. //---------------------------------------------------------------------------
  69. void TForm1::PanCameraAround(float dx, float dy)
  70. {
  71. pitch = pitch + dy;
  72. yaw = yaw - dx;
  73. if (pitch > 90)
  74. pitch = 90;
  75. if (pitch < -90)
  76. pitch = -90;
  77. if (yaw > 360)
  78. yaw = yaw - 360;
  79. if (yaw < 0)
  80. yaw = yaw + 360;
  81. GLCamera1->Up->SetVector(0, 1, 0);
  82. GLCamera1->Direction->SetVector(
  83. sin(DegToRad(yaw)), sin(DegToRad(pitch)), -cos(DegToRad(yaw)));
  84. LabelPitch->Caption = Format("Pitch: %3f", ARRAYOFCONST((pitch)));
  85. LabelYaw->Caption = Format("Yaw: %3f", ARRAYOFCONST((yaw)));
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TForm1::GLSceneViewer1MouseDown(
  89. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  90. {
  91. mx = X;
  92. my = Y;
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::GLSceneViewer1MouseMove(
  96. TObject* Sender, TShiftState Shift, int X, int Y)
  97. {
  98. float dx, dy, f;
  99. if (Shift.Contains(ssLeft)) {
  100. f = 0.2 * 40 / GLCamera1->FocalLength;
  101. dx = (X - mx) * f;
  102. dy = (Y - my) * f;
  103. PanCameraAround(dx, dy);
  104. }
  105. mx = X;
  106. my = Y;
  107. }
  108. //---------------------------------------------------------------------------
  109. //---------------------------------------------------------------------------
  110. void __fastcall TForm1::FormMouseWheel(TObject* Sender, TShiftState Shift,
  111. int WheelDelta, TPoint &MousePos, bool &Handled)
  112. {
  113. TrackBar1->Position = TrackBar1->Position + (int)(2 * WheelDelta / 120);
  114. }
  115. //---------------------------------------------------------------------------