fFxyC.cpp 4.8 KB

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