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 "GLBaseClasses"
  8. #pragma link "GLCadencer"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLExplosionFx"
  12. #pragma link "GLScene"
  13. #pragma link "GLVectorFileObjects"
  14. #pragma link "GLWin32Viewer"
  15. #pragma link "GLFile3DS"
  16. #pragma resource "*.dfm"
  17. TForm1 *Form1;
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20. : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::FormCreate(TObject *Sender)
  25. {
  26. SetGLSceneMediaDir();
  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 TForm1::CheckOnClick(TObject *Sender)
  39. {
  40. //turn on/off
  41. expl->Enabled = CheckOn->Checked;
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TForm1::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 TForm1::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 TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  65. int X, int Y)
  66. {
  67. vx = X; vy = Y;
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  71. const double newTime)
  72. {
  73. Viewer->Invalidate();
  74. StepBar->Position = expl->Step;
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::SpeedBarChange(TObject *Sender)
  78. {
  79. expl->Speed = (float) SpeedBar->Position / 10;
  80. }
  81. //---------------------------------------------------------------------------
  82. void __fastcall TForm1::MaxStepsBarChange(TObject *Sender)
  83. {
  84. expl->MaxSteps = MaxStepsBar->Position;
  85. StepBar->Max = MaxStepsBar->Position;
  86. }
  87. //---------------------------------------------------------------------------