Unit1.cpp 4.7 KB

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