fMeshExplosionC.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fMeshExplosionC.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. TFormMeshExplosion *FormMeshExplosion;
  17. //---------------------------------------------------------------------------
  18. __fastcall TFormMeshExplosion::TFormMeshExplosion(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TFormMeshExplosion::FormCreate(TObject *Sender)
  24. {
  25. TFileName Path = GetCurrentAssetPath();
  26. SetCurrentDir(Path + "\\model");
  27. //load mesh
  28. mesh->LoadFromFile("mushroom.3ds");
  29. //cache information
  30. Cache = new TGLMeshObjectList;
  31. Cache->Assign(mesh->MeshObjects);
  32. //default settings
  33. expl = (TGLBExplosionFX *)(mesh->Effects->Items[0]);
  34. expl->MaxSteps = 0;
  35. expl->Speed = 0.1;
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TFormMeshExplosion::CheckOnClick(TObject *Sender)
  39. {
  40. //turn on/off
  41. expl->Enabled = CheckOn->Checked;
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TFormMeshExplosion::Button1Click(TObject *Sender)
  45. {
  46. //reset simulation
  47. expl->Reset();
  48. CheckOn->Checked = false;
  49. //restore the mesh
  50. mesh->MeshObjects->Assign(Cache);
  51. mesh->StructureChanged();
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TFormMeshExplosion::ViewerMouseMove(TObject *Sender, TShiftState Shift, int X,
  55. int Y)
  56. {
  57. if (Shift.Contains(ssLeft))
  58. {
  59. Camera1->MoveAroundTarget(Y - vy, X - vx);
  60. vx = X; vy = Y;
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TFormMeshExplosion::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  65. int X, int Y)
  66. {
  67. vx = X; vy = Y;
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TFormMeshExplosion::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  71. const double newTime)
  72. {
  73. Viewer->Invalidate();
  74. StepBar->Position = expl->Step;
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TFormMeshExplosion::SpeedBarChange(TObject *Sender)
  78. {
  79. expl->Speed = (float) SpeedBar->Position / 10;
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TFormMeshExplosion::MaxStepsBarChange(TObject *Sender)
  83. {
  84. expl->MaxSteps = MaxStepsBar->Position;
  85. StepBar->Max = MaxStepsBar->Position;
  86. }
  87. //---------------------------------------------------------------------------