fCrossCursor.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. unit fCrossCursor;
  2. interface
  3. uses
  4. Windows,
  5. Messages,
  6. SysUtils,
  7. Variants,
  8. Classes,
  9. Math,
  10. Graphics,
  11. Controls,
  12. Forms,
  13. Dialogs,
  14. GLS.Scene,
  15. GLS.Cadencer,
  16. GLS.Objects,
  17. GLS.GeomObjects,
  18. GLS.SceneViewer,
  19. GLScene.VectorGeometry,
  20. GLScene.VectorTypes,
  21. GLS.FileTGA,
  22. GLS.Coordinates,
  23. GLS.BaseClasses;
  24. type
  25. TForm1 = class(TForm)
  26. GLScene1: TGLScene;
  27. vp: TGLSceneViewer;
  28. Camera: TGLCamera;
  29. Player: TGLDummyCube;
  30. Actor: TGLCone;
  31. GLCadencer1: TGLCadencer;
  32. GLLightSource1: TGLLightSource;
  33. PlaneTarget: TGLPlane;
  34. procedure vpMouseMove(Sender: TObject; Shift: TShiftState;
  35. X, Y: Integer);
  36. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  37. procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
  38. newTime: Double);
  39. private
  40. { Private declarations }
  41. public
  42. { Public declarations }
  43. end;
  44. var
  45. Form1: TForm1;
  46. _mx,_my:integer;
  47. _look:boolean=false;
  48. implementation
  49. {$R *.dfm}
  50. procedure TForm1.vpMouseMove(Sender:TObject;Shift:TShiftState;X,Y:Integer);
  51. var
  52. d,c:single;
  53. begin
  54. _mx:=x;
  55. _my:=y;
  56. _look:=true;
  57. {
  58. d := round(Form1.GLSceneViewer1.Width / 2);
  59. c := round(Form1.GLSceneViewer1.Height / 2);
  60. Form1.Actor.RollAngle := round(NormalizeDegAngle(radtodeg(arctan2(X - d + 32, Y - c + 32))));
  61. Form1.Caption := inttostr(round(NormalizeDegAngle(radtodeg(arctan2(X - d + 32, Y - c + 32)))));
  62. }
  63. end;
  64. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  65. begin
  66. glcadencer1.Enabled:=false;
  67. vp.Free;
  68. end;
  69. procedure TForm1.GLCadencer1Progress(Sender: TObject; const deltaTime,
  70. newTime: Double);
  71. var
  72. v: TVector4f;
  73. begin
  74. PlaneTarget.Roll(deltaTime * 50);
  75. if _look then
  76. begin
  77. vp.Buffer.ScreenVectorIntersectWithPlane(vectormake(_mx, vp.height - _my,
  78. 0), Player.AbsolutePosition, Player.AbsoluteUp, v);
  79. PlaneTarget.AbsolutePosition := v;
  80. Player.PointTo(v, Player.AbsoluteUp);
  81. _look := false;
  82. end;
  83. end;
  84. end.