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