Unit1.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <math.h>
  4. #pragma hdrstop
  5. #include "Unit1.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. String MediaPath = ExtractFilePath(ParamStr(0));
  32. String SubStr = "Samples";
  33. int I = MediaPath.Pos(SubStr);
  34. if (I != 0) {
  35. MediaPath.Delete(I+8,MediaPath.Length()-I);
  36. MediaPath += "Media\\";
  37. SetCurrentDir(MediaPath);
  38. }
  39. matLib->Materials->Items[0]->Material->Texture->Image->LoadFromFile("projector.tga");
  40. matLib->Materials->Items[1]->Material->Texture->Image->LoadFromFile("flare1.bmp");
  41. emitter1->Material->MaterialLibrary = matLib;
  42. emitter1->Material->LibMaterialName = "spot";
  43. emitter2->Material->MaterialLibrary = matLib;
  44. emitter2->Material->LibMaterialName = "spot2";
  45. emitter2->FOVy = 40;
  46. GLPlane1->Material->Texture->Image->LoadFromFile("cm_front.jpg");
  47. GLPlane2->Material->Texture->Image->LoadFromFile("cm_left.jpg");
  48. GLPlane3->Material->Texture->Image->LoadFromFile("cm_bottom.jpg");
  49. ProjLight->Emitters->AddEmitter(emitter1);
  50. ProjLight->Emitters->AddEmitter(emitter2);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  54. {
  55. Form1->Caption ="GLScene Projected Textures - "+ Format("%f", ARRAYOFCONST((viewer->FramesPerSecond())));
  56. viewer->ResetPerformanceMonitor();
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::viewerMouseDown(TObject *Sender,
  60. TMouseButton Button, TShiftState Shift, int X, int Y)
  61. {
  62. mk = 1;
  63. mx = X;
  64. my = Y;
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::viewerMouseUp(TObject *Sender, TMouseButton Button,
  68. TShiftState Shift, int X, int Y)
  69. {
  70. mk = 0;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TForm1::viewerMouseMove(TObject *Sender, TShiftState Shift,
  74. int X, int Y)
  75. {
  76. if (mk == 1)
  77. {
  78. if (Shift.Contains(ssLeft))
  79. GLCamera1->MoveAroundTarget(my - Y, mx - X);
  80. else if (Shift.Contains(ssRight))
  81. GLCamera1->AdjustDistanceToTarget(1.0 + (my - Y) * 0.01);
  82. }
  83. mx = X;
  84. my = Y;
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
  88. TShiftState Shift)
  89. {
  90. if (Key == VK_ADD)
  91. emitter1->FOVy = emitter1->FOVy + 5;
  92. else if (Key == VK_SUBTRACT)
  93. emitter1->FOVy = emitter1->FOVy - 5;
  94. if (Key == 'S')
  95. if (ProjLight->Style == ptsOriginal)
  96. ProjLight->Style = ptsInverse;
  97. else
  98. ProjLight->Style = ptsOriginal;
  99. }
  100. //---------------------------------------------------------------------------