fFogC.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. SetGLSceneMediaDir();
  27. GLMaterialLibrary1->AddTextureMaterial("glscene", "GLScene.bmp",true);
  28. for (X=-cNb; X<cNb; X++)
  29. for (Y=-cNb; Y<cNb; Y++)
  30. for (Z=-cNb; Z<cNb; Z++)
  31. if ((X & Y & Z) != 0)
  32. {
  33. Cube = (TGLCube *) GLDummyCube1->AddNewChild(__classid(TGLCube));
  34. Cube->Material->MaterialLibrary = GLMaterialLibrary1;
  35. Cube->Material->LibMaterialName = "GLScene";
  36. Cube->Position->SetPoint(X * cSpacing, Y * cSpacing, Z * cSpacing);
  37. Cube->CubeWidth = cEdgeLength;
  38. Cube->CubeHeight = cEdgeLength;
  39. Cube->CubeDepth = cEdgeLength;
  40. }
  41. ApplyFogSettings();
  42. }
  43. //---------------------------------------------------------------------------
  44. void TForm1::ApplyFogSettings(void)
  45. {
  46. TGLFogEnvironment *fog = GLSceneViewer1->Buffer->FogEnvironment;
  47. fog->FogMode = (TFogMode) RGFogMode->ItemIndex;
  48. fog->FogDistance = (TFogDistance) RGFogDistance->ItemIndex;
  49. fog->FogColor->AsWinColor = SFogColor->Brush->Color;
  50. fog->FogColor->Alpha = (float)StrToInt(EFogDensity->Text) / 1000;
  51. if (CBApplyToBackground->Checked)
  52. GLSceneViewer1->Buffer->BackgroundColor = SFogColor->Brush->Color;
  53. fog->FogStart = StrToInt(EFogStart->Text);
  54. fog->FogEnd = StrToInt(EFogEnd->Text);
  55. GLSceneViewer1->Buffer->FogEnable = CBFogEnable->Checked;
  56. GLSceneViewer1->Invalidate();
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender,
  60. TMouseButton Button, TShiftState Shift, int X, int Y)
  61. {
  62. mx = X;
  63. my = Y;
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender,
  67. TShiftState Shift, int X, int Y)
  68. {
  69. if (Shift.Contains(ssLeft))
  70. {
  71. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  72. mx = X;
  73. my = Y;
  74. }
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::CBFogEnableClick(TObject *Sender)
  78. {
  79. ApplyFogSettings();
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TForm1::EFogStartChange(TObject *Sender)
  83. {
  84. if (((TEdit *)(Sender))->Text != "")
  85. ApplyFogSettings();
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TForm1::SFogColorMouseDown(TObject *Sender,
  89. TMouseButton Button, TShiftState Shift, int X, int Y)
  90. {
  91. if (ColorDialog1->Execute())
  92. {
  93. SFogColor->Brush->Color = ColorDialog1->Color;
  94. ApplyFogSettings();
  95. }
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TForm1::RGFogModeClick(TObject *Sender)
  99. {
  100. ApplyFogSettings();
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TForm1::CBApplyToBackgroundClick(TObject *Sender)
  104. {
  105. ApplyFogSettings();
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TForm1::CBTextureEnabledClick(TObject *Sender)
  109. {
  110. GLMaterialLibrary1->Materials->Items[0]->Material->Texture->Enabled = CBTextureEnabled->Checked;
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TForm1::CBTextureIgnoreFogClick(TObject *Sender)
  114. {
  115. if (CBTextureIgnoreFog->Checked)
  116. GLMaterialLibrary1->Materials->Items[0]->Material->MaterialOptions << moIgnoreFog;
  117. else
  118. GLMaterialLibrary1->Materials->Items[0]->Material->MaterialOptions >> moIgnoreFog;
  119. ApplyFogSettings();
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  123. TPoint &MousePos, bool &Handled)
  124. {
  125. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta/120));
  126. }
  127. //---------------------------------------------------------------------------