Unit1.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SkyDome"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::GenerateCubeMap()
  24. {
  25. // Don't do anything if cube maps aren't supported
  26. if (!CubmapSupported) {
  27. if (!CubeMapWarnDone)
  28. ShowMessage("Your graphics hardware does not support cube maps...");
  29. CubeMapWarnDone = true;
  30. exit;
  31. }
  32. // Here we generate the new cube map, from CubeMapCamera (a child of the
  33. // teapot in the scene hierarchy)
  34. // hide the teapot while rendering the cube map
  35. Teapot1->Visible = false;
  36. // render cube map to the teapot's texture
  37. GLMemoryViewer1->RenderCubeMapTextures(Teapot1->Material->Texture);
  38. // teapot visible again
  39. Teapot1->Material->Texture->Disabled = false;
  40. Teapot1->Visible = true;
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  44. const double newTime)
  45. {
  46. if (CBDynamic->Checked) {
  47. // make things move
  48. Teapot1->Position->Y = 2*Sin(newTime);
  49. Torus1->RollAngle = newTime*15;
  50. // generate the cube map
  51. GenerateCubeMap();
  52. }
  53. GLSceneViewer1->Invalidate();
  54. }
  55. //---------------------------------------------------------------------------
  56. // Standard issue mouse movements
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  59. TShiftState Shift, int X, int Y)
  60. {
  61. mx = X;
  62. my = Y;
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  66. int X, int Y)
  67. {
  68. if (Shift.Contains(ssLeft))
  69. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  70. else if (Shift.Contains(ssRight))
  71. GLCamera1->RotateTarget(my-Y, mx-X, 0);
  72. mx=X; my=Y;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  76. TPoint &MousePos, bool &Handled)
  77. {
  78. GLCamera1->
  79. AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  83. {
  84. LabelFPS->Caption = GLSceneViewer1->FramesPerSecondText();
  85. GLSceneViewer1->ResetPerformanceMonitor();
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TForm1::GLSceneViewer1BeforeRender(TObject *Sender)
  89. {
  90. CubmapSupported = !GL_ARB_texture_cube_map;
  91. GLSceneViewer1->BeforeRender = NULL;
  92. }
  93. //---------------------------------------------------------------------------