fProjTexturesC.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <math.h>
  4. #pragma hdrstop
  5. #include "fProjTexturesC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.FileTGA"
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. float ang;
  12. int mx, my, mk;
  13. //---------------------------------------------------------------------------
  14. __fastcall TForm1::TForm1(TComponent* Owner)
  15. : TForm(Owner)
  16. {
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender,
  20. const double deltaTime, const double newTime)
  21. {
  22. ang = ang + deltaTime*20;
  23. Light->Position->Y = sin(DegToRad(ang));
  24. Light->Position->X = cos(DegToRad(ang));
  25. light2->Pitch(deltaTime*20);
  26. viewer->Invalidate();
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::FormCreate(TObject *Sender)
  30. {
  31. TFileName Path = GetCurrentAssetPath();
  32. SetCurrentDir(Path + "\\texture");
  33. matLib->TexturePaths = GetCurrentDir();
  34. matLib->Materials->Items[0]->Material->Texture->Image->LoadFromFile("projector.tga");
  35. matLib->Materials->Items[1]->Material->Texture->Image->LoadFromFile("flare1.bmp");
  36. emitter1->Material->MaterialLibrary = matLib;
  37. emitter1->Material->LibMaterialName = "spot";
  38. emitter2->Material->MaterialLibrary = matLib;
  39. emitter2->Material->LibMaterialName = "spot2";
  40. emitter2->FOVy = 40;
  41. // cubemap
  42. SetCurrentDir(Path + "\\cubemap");
  43. GLPlane1->Material->Texture->Image->LoadFromFile("cm_front.jpg");
  44. GLPlane2->Material->Texture->Image->LoadFromFile("cm_left.jpg");
  45. GLPlane3->Material->Texture->Image->LoadFromFile("cm_bottom.jpg");
  46. ProjLight->Emitters->AddEmitter(emitter1);
  47. ProjLight->Emitters->AddEmitter(emitter2);
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  51. {
  52. Form1->Caption ="GLScene Projected Textures - "+ Format("%f", ARRAYOFCONST((viewer->FramesPerSecond())));
  53. viewer->ResetPerformanceMonitor();
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm1::viewerMouseDown(TObject *Sender,
  57. TMouseButton Button, TShiftState Shift, int X, int Y)
  58. {
  59. mk = 1;
  60. mx = X;
  61. my = Y;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::viewerMouseUp(TObject *Sender, TMouseButton Button,
  65. TShiftState Shift, int X, int Y)
  66. {
  67. mk = 0;
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::viewerMouseMove(TObject *Sender, TShiftState Shift,
  71. int X, int Y)
  72. {
  73. if (mk == 1)
  74. {
  75. if (Shift.Contains(ssLeft))
  76. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  77. else if (Shift.Contains(ssRight))
  78. GLCamera1->AdjustDistanceToTarget(1.0 + (my - Y) * 0.01);
  79. }
  80. mx = X;
  81. my = Y;
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
  85. TShiftState Shift)
  86. {
  87. if (Key == VK_ADD)
  88. emitter1->FOVy = emitter1->FOVy + 5;
  89. else if (Key == VK_SUBTRACT)
  90. emitter1->FOVy = emitter1->FOVy - 5;
  91. if (Key == 'S')
  92. if (ProjLight->Style == ptsOriginal)
  93. ProjLight->Style = ptsInverse;
  94. else
  95. ProjLight->Style = ptsOriginal;
  96. }
  97. //---------------------------------------------------------------------------