fFogC.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fFogC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.Cadencer"
  8. #pragma link "GLS.Objects"
  9. #pragma link "GLS.Scene"
  10. #pragma link "GLS.Texture"
  11. #pragma link "GLS.SceneViewer"
  12. #pragma link "GLS.BaseClasses"
  13. #pragma link "GLS.Coordinates"
  14. #pragma link "GLS.Material"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. #define cSpacing 2
  18. #define cEdgeLength 0.7
  19. #define cNb 4
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. int X, Y, Z;
  25. TGLCube *Cube;
  26. TFileName Path = GetCurrentAssetPath();
  27. SetCurrentDir(Path + "\\texture");
  28. GLMaterialLibrary1->TexturePaths = GetCurrentDir();
  29. GLMaterialLibrary1->AddTextureMaterial("glscene", "glscene.bmp");
  30. for (X=-cNb; X<cNb; X++)
  31. for (Y=-cNb; Y<cNb; Y++)
  32. for (Z=-cNb; Z<cNb; Z++)
  33. if ((X & Y & Z) != 0)
  34. {
  35. Cube = (TGLCube *) GLDummyCube1->AddNewChild(__classid(TGLCube));
  36. Cube->Material->MaterialLibrary = GLMaterialLibrary1;
  37. Cube->Material->LibMaterialName = "glscene";
  38. Cube->Position->SetPoint(X * cSpacing, Y * cSpacing, Z * cSpacing);
  39. Cube->CubeWidth = cEdgeLength;
  40. Cube->CubeHeight = cEdgeLength;
  41. Cube->CubeDepth = cEdgeLength;
  42. }
  43. ApplyFogSettings();
  44. }
  45. //---------------------------------------------------------------------------
  46. void TForm1::ApplyFogSettings(void)
  47. {
  48. TGLFogEnvironment *fog = GLSceneViewer1->Buffer->FogEnvironment;
  49. fog->FogMode = (TFogMode) RGFogMode->ItemIndex;
  50. fog->FogDistance = (TFogDistance) RGFogDistance->ItemIndex;
  51. fog->FogColor->AsWinColor = SFogColor->Brush->Color;
  52. fog->FogColor->Alpha = (float)StrToInt(EFogDensity->Text) / 1000;
  53. if (CBApplyToBackground->Checked)
  54. GLSceneViewer1->Buffer->BackgroundColor = SFogColor->Brush->Color;
  55. fog->FogStart = StrToInt(EFogStart->Text);
  56. fog->FogEnd = StrToInt(EFogEnd->Text);
  57. GLSceneViewer1->Buffer->FogEnable = CBFogEnable->Checked;
  58. GLSceneViewer1->Invalidate();
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender,
  62. TMouseButton Button, TShiftState Shift, int X, int Y)
  63. {
  64. mx = X;
  65. my = Y;
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender,
  69. TShiftState Shift, int X, int Y)
  70. {
  71. if (Shift.Contains(ssLeft))
  72. {
  73. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  74. mx = X;
  75. my = Y;
  76. }
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TForm1::CBFogEnableClick(TObject *Sender)
  80. {
  81. ApplyFogSettings();
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::EFogStartChange(TObject *Sender)
  85. {
  86. if (((TEdit *)(Sender))->Text != "")
  87. ApplyFogSettings();
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::SFogColorMouseDown(TObject *Sender,
  91. TMouseButton Button, TShiftState Shift, int X, int Y)
  92. {
  93. if (ColorDialog1->Execute())
  94. {
  95. SFogColor->Brush->Color = ColorDialog1->Color;
  96. ApplyFogSettings();
  97. }
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TForm1::RGFogModeClick(TObject *Sender)
  101. {
  102. ApplyFogSettings();
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TForm1::CBApplyToBackgroundClick(TObject *Sender)
  106. {
  107. ApplyFogSettings();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TForm1::CBTextureEnabledClick(TObject *Sender)
  111. {
  112. GLMaterialLibrary1->Materials->Items[0]->Material->Texture->Enabled = CBTextureEnabled->Checked;
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TForm1::CBTextureIgnoreFogClick(TObject *Sender)
  116. {
  117. if (CBTextureIgnoreFog->Checked)
  118. GLMaterialLibrary1->Materials->Items[0]->Material->MaterialOptions << moIgnoreFog;
  119. else
  120. GLMaterialLibrary1->Materials->Items[0]->Material->MaterialOptions >> moIgnoreFog;
  121. ApplyFogSettings();
  122. }
  123. //---------------------------------------------------------------------------
  124. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  125. TPoint &MousePos, bool &Handled)
  126. {
  127. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta/120));
  128. }
  129. //---------------------------------------------------------------------------