fTorqueC.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fTorqueC.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.Objects"
  11. #pragma link "GLS.GeomObjects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.SceneViewer"
  14. #pragma link "GLS.VectorFileObjects"
  15. #pragma link "GLS.BitmapFont"
  16. #pragma link "GLS.HUDObjects"
  17. #pragma resource "*.dfm"
  18. TFormTorqueC *FormTorqueC;
  19. //---------------------------------------------------------------------------
  20. __fastcall TFormTorqueC::TFormTorqueC(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TFormTorqueC::FormCreate(TObject *Sender)
  26. {
  27. // Initialize last time
  28. lastTime = 24*3600*(Now());
  29. // Initialize rotation dampings...
  30. // ...using properties...
  31. GetOrCreateInertia(Hexahedron->Behaviours)->RotationDamping->Constant = 1;
  32. GetOrCreateInertia(Hexahedron->Behaviours)->RotationDamping->Linear = 1;
  33. GetOrCreateInertia(Hexahedron->Behaviours)->RotationDamping->Quadratic = 0;
  34. // ...using helper function on the TGLBehaviours...
  35. GetOrCreateInertia(Dodecahedron->Behaviours)->RotationDamping->SetDamping(10, 0, 0.01);
  36. // ...or using helper function directly on the TGLBaseSceneObject
  37. GetOrCreateInertia(Octahedron)->RotationDamping->SetDamping(0, 0, 0.01);
  38. GetOrCreateInertia(Icosahedron)->RotationDamping->SetDamping(10, 0, 0.01);
  39. GetOrCreateInertia(Tetrahedron)->RotationDamping->SetDamping(0, 0, 0.01);
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TFormTorqueC::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  43. int X, int Y)
  44. {
  45. // Mouse moved, get what's underneath
  46. pickedObject = GLSceneViewer1->Buffer->GetPickedObject(X, Y);
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TFormTorqueC::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  50. const double newTime)
  51. {
  52. // apply some "torque" to the pickedObject if any
  53. if (pickedObject)
  54. GetOrCreateInertia(pickedObject)->ApplyTorque(deltaTime, 200, 0, 0);
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TFormTorqueC::CheckBox1Click(TObject *Sender)
  58. {
  59. int i;
  60. Single mass;
  61. if (CheckBox1->Checked)
  62. mass = 2;
  63. else
  64. mass = 1;
  65. // all our objects are child of the DummyCube1
  66. for (i=0; i < DummyCube1->Count-1; i++)
  67. GetOrCreateInertia(DummyCube1->Children[i])->Mass = mass;
  68. }
  69. //---------------------------------------------------------------------------