fPathControlD.pas 2.9 KB

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