Unit1.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.ExplosionFx"
  11. #pragma link "GLS.Scene"
  12. #pragma link "GLS.VectorFileObjects"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma link "GLS.File3DS"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25. SetGLSceneMediaDir();
  26. //load mesh
  27. mesh->LoadFromFile("mushroom.3ds");
  28. //cache information
  29. Cache = new TGLMeshObjectList;
  30. Cache->Assign(mesh->MeshObjects);
  31. //default settings
  32. expl = (TGLBExplosionFX *)(mesh->Effects->Items[0]);
  33. expl->MaxSteps = 0;
  34. expl->Speed = 0.1;
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::CheckOnClick(TObject *Sender)
  38. {
  39. //turn on/off
  40. expl->Enabled = CheckOn->Checked;
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TForm1::Button1Click(TObject *Sender)
  44. {
  45. //reset simulation
  46. expl->Reset();
  47. CheckOn->Checked = false;
  48. //restore the mesh
  49. mesh->MeshObjects->Assign(Cache);
  50. mesh->StructureChanged();
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TForm1::ViewerMouseMove(TObject *Sender, TShiftState Shift, int X,
  54. int Y)
  55. {
  56. if (Shift.Contains(ssLeft))
  57. {
  58. Camera1->MoveAroundTarget(Y - vy, X - vx);
  59. vx = X; vy = Y;
  60. }
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  64. int X, int Y)
  65. {
  66. vx = X; vy = Y;
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  70. const double newTime)
  71. {
  72. Viewer->Invalidate();
  73. StepBar->Position = expl->Step;
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TForm1::SpeedBarChange(TObject *Sender)
  77. {
  78. expl->Speed = (float) SpeedBar->Position / 10;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TForm1::MaxStepsBarChange(TObject *Sender)
  82. {
  83. expl->MaxSteps = MaxStepsBar->Position;
  84. StepBar->Max = MaxStepsBar->Position;
  85. }
  86. //---------------------------------------------------------------------------