Unit1.pas 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. unit Unit1;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Classes,
  6. Vcl.Graphics,
  7. Vcl.Controls,
  8. Vcl.Forms,
  9. Vcl.Dialogs,
  10. GLS.Scene,
  11. GLS.Objects,
  12. GLS.PersistentClasses,
  13. GLS.Joystick,
  14. GLS.GeomObjects,
  15. GLS.Cadencer,
  16. GLS.SceneViewer,
  17. GLS.Coordinates,
  18. GLS.BaseClasses;
  19. type
  20. TForm1 = class(TForm)
  21. GLScene1: TGLScene;
  22. GLSceneViewer1: TGLSceneViewer;
  23. Joystick1: TGLJoystick;
  24. GLCamera1: TGLCamera;
  25. GLLightSource1: TGLLightSource;
  26. DummyCube1: TGLDummyCube;
  27. Cube1: TGLCube;
  28. Cylinder1: TGLCylinder;
  29. Sphere1: TGLSphere;
  30. DummyCube2: TGLDummyCube;
  31. Sphere2: TGLSphere;
  32. Sphere3: TGLSphere;
  33. Sphere4: TGLSphere;
  34. DummyCube3: TGLDummyCube;
  35. GLCadencer1: TGLCadencer;
  36. procedure FormCreate(Sender: TObject);
  37. procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
  38. newTime: Double);
  39. procedure Joystick1JoystickButtonChange(Sender: TObject; JoyID: TJoystickID;
  40. Buttons: TJoystickButtons; XDeflection, YDeflection: Integer);
  41. private
  42. public
  43. end;
  44. var
  45. Form1: TForm1;
  46. implementation
  47. {$R *.DFM}
  48. procedure TForm1.FormCreate(Sender: TObject);
  49. begin
  50. if Joystick1.Capture=False then begin
  51. ShowMessage('Connect a Joystick!');
  52. Application.Terminate;
  53. Exit;
  54. end;
  55. // setup default sphere colors
  56. Joystick1JoystickButtonChange(Self, Joystick1.JoystickID, [], 0, 0);
  57. end;
  58. procedure TForm1.GLCadencer1Progress(Sender: TObject; const deltaTime,
  59. newTime: Double);
  60. begin
  61. // Rotate our 3d stick (=cylinder), a dummycube is used as its rotation axis
  62. DummyCube1.PitchAngle:=-Joystick1.XPosition/3;
  63. DummyCube1.RollAngle:=Joystick1.YPosition/3;
  64. end;
  65. procedure TForm1.Joystick1JoystickButtonChange(Sender: TObject;
  66. JoyID: TJoystickID; Buttons: TJoystickButtons; XDeflection,
  67. YDeflection: Integer);
  68. const
  69. cPressedColor : array [False..True] of Integer = (clGray, clWhite);
  70. var
  71. button : TJoystickButton;
  72. i : Integer;
  73. begin
  74. // Browse all buttons and adjusts matching spheres color
  75. // All the spheres are accessed in an arrayed fashion (I made them
  76. // child of a single dummycube)
  77. i := 0;
  78. for button := jbButton1 to jbButton4 do
  79. begin
  80. with TGLSphere(DummyCube2.Children[i]).Material.FrontProperties.Diffuse do
  81. AsWinColor := cPressedColor[button in Buttons];
  82. Inc(i);
  83. end;
  84. end;
  85. end.