fcFxy.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fcFxy.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.Graph"
  8. #pragma link "GLS.Objects"
  9. #pragma link "GLS.Scene"
  10. #pragma link "GLS.SceneViewer"
  11. #pragma link "GLS.BaseClasses"
  12. #pragma link "GLS.Coordinates"
  13. #pragma link "GLS.AsyncTimer"
  14. #pragma resource "*.dfm"
  15. TFormFxy* FormFxy;
  16. //---------------------------------------------------------------------------
  17. __fastcall TFormFxy::TFormFxy(TComponent* Owner) : TForm(Owner) {}
  18. //---------------------------------------------------------------------------
  19. void __fastcall TFormFxy::FormCreate(TObject* Sender)
  20. {
  21. rgFormulaClick(Sender);
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TFormFxy::Formula0(const float x, const float y, float &z,
  25. TVector4f &color, TTexPoint &texPoint)
  26. {
  27. // 0ro formula
  28. z = VectorNorm(x, y);
  29. z = x * y;
  30. VectorLerp(clrBlue, clrRed, (z + 1) / 2, color);
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TFormFxy::Formula1(const float x, const float y, float &z,
  34. TVector4f &color, TTexPoint &texPoint)
  35. {
  36. // 1st formula
  37. z = VectorNorm(x, y);
  38. z = x * y * z; // or z = (x*x)*(y*y);
  39. VectorLerp(clrBlue, clrRed, (z + 1) / 2, color);
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TFormFxy::Formula2(const float x, const float y, float &z,
  43. TVector4f &color, TTexPoint &texPoint)
  44. {
  45. // 2nd formula
  46. z = VectorNorm(x, y);
  47. z = sin(z * 12) / (2 * (z * 6.28 + 1));
  48. VectorLerp(clrBlue, clrRed, (z + 1) / 2, color);
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TFormFxy::Formula3(const float x, const float y, float &z,
  52. TVector4f &color, TTexPoint &texPoint)
  53. {
  54. // 3rd formula
  55. z = VectorNorm(x, y);
  56. z = (pow(x, 2) + pow(y, 2)) * sin(8 * atan2(x, y));
  57. VectorLerp(clrBlue, clrRed, (z + 1) / 2, color);
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TFormFxy::chbCenterClick(TObject* Sender)
  61. {
  62. if (chbCenter->Checked) {
  63. XZGrid->YSamplingScale->Origin = 0;
  64. YZGrid->XSamplingScale->Origin = 0;
  65. XYGrid->ZSamplingScale->Origin = 0;
  66. } else {
  67. XZGrid->YSamplingScale->Origin = -1;
  68. YZGrid->XSamplingScale->Origin = -1;
  69. XYGrid->ZSamplingScale->Origin = -1;
  70. }
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TFormFxy::TrackBarYChange(TObject* Sender)
  74. {
  75. XYGrid->ZSamplingScale->Origin = -((float)TrackBarY->Position / 10);
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TFormFxy::TrackBarXChange(TObject* Sender)
  79. {
  80. XZGrid->YSamplingScale->Origin = -((float)TrackBarX->Position / 10);
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TFormFxy::TrackBarZChange(TObject* Sender)
  84. {
  85. YZGrid->XSamplingScale->Origin = -((float)TrackBarZ->Position / 10);
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TFormFxy::ViewerMouseDown(
  89. TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
  90. {
  91. mx = X;
  92. my = Y;
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TFormFxy::ViewerMouseMove(
  96. TObject* Sender, TShiftState Shift, int X, int Y)
  97. {
  98. if (Shift.Contains(ssLeft))
  99. Camera->MoveAroundTarget(my - Y, mx - X);
  100. else if (Shift.Contains(ssRight))
  101. Camera->RotateTarget(my - Y, mx - X, 0);
  102. mx = X;
  103. my = Y;
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TFormFxy::FormMouseWheel(TObject* Sender, TShiftState Shift,
  107. int WheelDelta, TPoint &MousePos, bool &Handled)
  108. {
  109. Camera->AdjustDistanceToTarget(Power(1.1, (WheelDelta / 120.0)));
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TFormFxy::rgFormulaClick(TObject *Sender)
  113. {
  114. switch (rgFormula->ItemIndex) {
  115. case 0:
  116. HeightField->OnGetHeight = Formula0;
  117. break;
  118. case 1:
  119. HeightField->OnGetHeight = Formula1;
  120. break;
  121. case 2:
  122. HeightField->OnGetHeight = Formula2;
  123. break;
  124. case 3:
  125. HeightField->OnGetHeight = Formula3;
  126. break;
  127. default:;
  128. }
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TFormFxy::rgPolygonModeClick(TObject* Sender)
  132. {
  133. switch (rgPolygonMode->ItemIndex) {
  134. case 0:
  135. HeightField->Material->PolygonMode = pmFill;
  136. break;
  137. case 1:
  138. HeightField->Material->PolygonMode = pmLines;
  139. break;
  140. case 2:
  141. HeightField->Material->PolygonMode = pmPoints;
  142. break;
  143. default:;
  144. }
  145. HeightField->StructureChanged();
  146. }
  147. //---------------------------------------------------------------------------