Unit1.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 "GLBehaviours"
  10. #pragma link "GLBitmapFont"
  11. #pragma link "GLBlur"
  12. #pragma link "GLCadencer"
  13. #pragma link "GLCoordinates"
  14. #pragma link "GLCrossPlatform"
  15. #pragma link "GLHUDObjects"
  16. #pragma link "GLNavigator"
  17. #pragma link "GLObjects"
  18. #pragma link "GLParticleFX"
  19. #pragma link "GLPerlinPFX"
  20. #pragma link "GLScene"
  21. #pragma link "GLSpaceText"
  22. #pragma link "GLWin32Viewer"
  23. #include "GLKeyboard.hpp"
  24. #pragma resource "*.dfm"
  25. TForm1 *Form1;
  26. int cRunBoost = 10;
  27. int cWalkStep = 20;
  28. int cStrafeStep =20;
  29. //---------------------------------------------------------------------------
  30. __fastcall TForm1::TForm1(TComponent* Owner)
  31. : TForm(Owner)
  32. {
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::FormCreate(TObject *Sender)
  36. {
  37. chkFloorClick(Sender);
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TForm1::chkFloorClick(TObject *Sender)
  41. {
  42. GLPlane1->Visible = chkFloor->Checked;
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::chkBlurClick(TObject *Sender)
  46. {
  47. GLBlur1->Visible = chkBlur->Checked;
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::chkMouseLookClick(TObject *Sender)
  51. {
  52. GLUserInterface1->MouseLookActive = chkMouseLook->Checked;
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  56. {
  57. Caption = "PFXGallery FPS - " + IntToStr(Round(GLSceneViewer1->FramesPerSecond()));
  58. GLSceneViewer1->ResetPerformanceMonitor();
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  62. const double newTime)
  63. {
  64. HandleKeys(deltaTime);
  65. GLUserInterface1->MouseLook();
  66. GLSceneViewer1->Invalidate();
  67. GLUserInterface1->MouseUpdate();
  68. GLSceneViewer1->Invalidate();
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::HandleKeys(double deltaTime)
  72. {
  73. float boost;
  74. if (IsKeyDown(vkEscape)) {
  75. chkMouseLook->Checked = false;
  76. chkMouseLookClick(this);
  77. }
  78. if (IsKeyDown(vkShift))
  79. boost = cRunBoost*deltaTime;
  80. else
  81. if (IsKeyDown(vkControl))
  82. boost = cRunBoost*0.01*deltaTime;
  83. else
  84. boost = deltaTime;
  85. if (IsKeyDown('W'))
  86. GLCamera1->Move(cWalkStep*boost);
  87. if (IsKeyDown('S'))
  88. GLCamera1->Move(-cWalkStep*boost);
  89. if (IsKeyDown('A'))
  90. GLCamera1->Slide(-cStrafeStep*boost);
  91. if (IsKeyDown('D'))
  92. GLCamera1->Slide(cStrafeStep*boost);
  93. }
  94. //---------------------------------------------------------------------------