Unit1.cpp 2.6 KB

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