fPathControl.pas 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. unit fPathControl;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. Vcl.Controls,
  8. Vcl.Forms,
  9. Vcl.ComCtrls,
  10. Vcl.ExtCtrls,
  11. Vcl.StdCtrls,
  12. Vcl.Buttons,
  13. GLS.Scene,
  14. GLS.Objects,
  15. GLS.VectorGeometry,
  16. GLS.Cadencer,
  17. GLS.Behaviours,
  18. GLS.Graph,
  19. GLS.Movement,
  20. GLS.VectorTypes,
  21. GLS.SceneViewer,
  22. GLS.Coordinates,
  23. GLS.BaseClasses,
  24. GLS.Utils,
  25. GLS.SimpleNavigation;
  26. type
  27. TFormPathControl = class(TForm)
  28. GLScene1: TGLScene;
  29. GLSceneViewer1: TGLSceneViewer;
  30. Cube2: TGLCube;
  31. GLCamera1: TGLCamera;
  32. GLLightSource1: TGLLightSource;
  33. DummyCube1: TGLDummyCube;
  34. GLCadencer1: TGLCadencer;
  35. MoveBtn: TBitBtn;
  36. Sphere1: TGLSphere;
  37. GLSimpleNavigation1: TGLSimpleNavigation;
  38. procedure FormActivate(Sender: TObject);
  39. procedure MoveBtnClick(Sender: TObject);
  40. private
  41. procedure PathTravelStop(Sender: TObject; Path: TGLMovementPath; var Looped: Boolean);
  42. procedure PathAllTravelledOver(Sender: TObject);
  43. public
  44. end;
  45. var
  46. FormPathControl: TFormPathControl;
  47. implementation
  48. {$R *.DFM}
  49. procedure TFormPathControl.FormActivate(Sender: TObject);
  50. var
  51. Movement: TGLMovement;
  52. Path: TGLMovementPath;
  53. Node: TGLPathNode;
  54. begin
  55. // Create a movement, a path and the first node of the path.
  56. Movement := GetOrCreateMovement(Cube2);
  57. Movement.OnPathTravelStop := PathTravelStop;
  58. Movement.OnAllPathTravelledOver := PathAllTravelledOver;
  59. Path := Movement.AddPath;
  60. Path.ShowPath := True;
  61. // Path.StartTime := 2;
  62. // Path.Looped := True;
  63. Node := Path.AddNodeFromObject(Cube2);
  64. Node.Speed := 4.0;
  65. // Add a node.
  66. Node := Path.AddNode;
  67. Node.Speed := 4.0;
  68. Node.PositionAsVector := VectorMake(-10, 0, 0, 1);
  69. Node.RotationAsVector := VectorMake(0, 0, 0);
  70. // Add a node.
  71. Node := Path.AddNode;
  72. Node.Speed := 4.0;
  73. Node.PositionAsVector := VectorMake(0, 5, - 5);
  74. Node.RotationAsVector := VectorMake(0, 90, 0);
  75. // Add a node.
  76. Node := Path.AddNode;
  77. Node.Speed := 4.0;
  78. Node.PositionAsVector := VectorMake(6, - 5, 2);
  79. Node.RotationAsVector := VectorMake(0, 180, 0);
  80. // Add a node.
  81. Node := Path.AddNode;
  82. Node.Speed := 4.0;
  83. Node.PositionAsVector := VectorMake(-6, 0, 0);
  84. Node.RotationAsVector := VectorMake(0, 259, 0);
  85. // Activatived the current path.
  86. Movement.ActivePathIndex := 0;
  87. end;
  88. procedure TFormPathControl.MoveBtnClick(Sender: TObject);
  89. var
  90. Movement: TGLMovement;
  91. begin
  92. Movement := GetMovement(Cube2);
  93. if Assigned(Movement) then begin
  94. Movement.StartPathTravel;
  95. GLCadencer1.Enabled := True;
  96. end;
  97. end;
  98. procedure TFormPathControl.PathTravelStop(Sender: TObject; Path: TGLMovementPath; var Looped: Boolean);
  99. begin
  100. if not Application.Terminated then
  101. InformationDlg('Path Travel Stopped');
  102. end;
  103. procedure TFormPathControl.PathAllTravelledOver(Sender: TObject);
  104. begin
  105. if not Application.Terminated then
  106. InformationDlg('All Path(es) Traveled Over');
  107. end;
  108. end.