fPanoViewerC.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::BtnLoadClick(TObject *Sender)
  26. {
  27. OpenPictureDialog1->InitialDir = ExtractFilePath(ParamStr(0));
  28. OpenPictureDialog1->FileName = "sejourstmathieu2048.jpg";
  29. if (OpenPictureDialog1->Execute())
  30. GLMaterialLibrary1->Materials->Items[0]->Material->
  31. Texture->Image->LoadFromFile(OpenPictureDialog1->FileName);
  32. }
  33. //---------------------------------------------------------------------------
  34. void __fastcall TForm1::TrackBar1Change(TObject *Sender)
  35. {
  36. GLCamera1->FocalLength = TrackBar1->Position;
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender,
  40. const double deltaTime, const double newTime)
  41. {
  42. const int step_size = 20;
  43. float delta;
  44. float dx, dy;
  45. delta = step_size * 40/GLCamera1->FocalLength * deltaTime;
  46. dx = 0;
  47. dy = 0;
  48. if (IsKeyDown(VK_LEFT) ) dx = dx+delta;
  49. if (IsKeyDown(VK_UP) ) dy = dy+delta;
  50. if (IsKeyDown(VK_RIGHT)) dx = dx-delta;
  51. if (IsKeyDown(VK_DOWN) ) dy = dy-delta;
  52. PanCameraAround(dx, dy);
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
  56. TShiftState Shift)
  57. {
  58. Key = 0; // all keys handled by Form1
  59. }
  60. //---------------------------------------------------------------------------
  61. void TForm1::PanCameraAround(float dx, float dy)
  62. {
  63. pitch = pitch+dy;
  64. yaw = yaw-dx;
  65. if (pitch>90) pitch = 90;
  66. if (pitch<-90) pitch = -90;
  67. if (yaw>360) yaw = yaw-360;
  68. if (yaw<0) yaw = yaw+360;
  69. GLCamera1->Up->SetVector(0, 1, 0);
  70. GLCamera1->Direction->SetVector( sin(DegToRad(yaw)),
  71. sin(DegToRad(pitch)),
  72. -cos(DegToRad(yaw)));
  73. LabelPitch->Caption = Format("Pitch: %3f", ARRAYOFCONST((pitch)));
  74. LabelYaw->Caption = Format("Yaw: %3f", ARRAYOFCONST((yaw)));
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender,
  78. TMouseButton Button, TShiftState Shift, int X, int Y)
  79. {
  80. mx = X;
  81. my = Y;
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender,
  85. TShiftState Shift, int X, int Y)
  86. {
  87. float dx, dy, f;
  88. if (Shift.Contains(ssLeft))
  89. {
  90. f = 0.2*40/GLCamera1->FocalLength;
  91. dx = (X-mx)*f;
  92. dy = (Y-my)*f;
  93. PanCameraAround(dx, dy);
  94. }
  95. mx = X;
  96. my = Y;
  97. }
  98. //---------------------------------------------------------------------------
  99. //---------------------------------------------------------------------------
  100. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  101. TPoint &MousePos, bool &Handled)
  102. {
  103. TrackBar1->Position = TrackBar1->Position+(int)(2*WheelDelta/120);
  104. }
  105. //---------------------------------------------------------------------------