GBE.PlayerPosition.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. unit GBE.PlayerPosition;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Classes,
  6. System.Math.Vectors,
  7. FMX.Types,
  8. FMX.Controls3D,
  9. FMX.Objects3D;
  10. type
  11. TGBETypePosition = (firstPerson, thirdPerson, other);
  12. TGBEPlayerPosition = class(TDummy)
  13. private
  14. fDummyOrientation, fNextPosition, fPositionDirection: TDummy;
  15. fCamera: TCamera;
  16. fTypePosition: TGBETypePosition;
  17. fWidth: single;
  18. fDepth: single;
  19. fHeight: single;
  20. function GetPositionCamera: TPoint3D;
  21. procedure SetPositionCamera(const Value: TPoint3D);
  22. function GetAngleOfView: single;
  23. procedure SetAngleOfView(const Value: single);
  24. procedure SetTypePosition(const Value: TGBETypePosition);
  25. procedure SetWidth(const Value: single);
  26. procedure SetDepth(const Value: single);
  27. procedure SetHeight(const Value: single);
  28. protected
  29. public
  30. constructor Create(AOwner: TComponent); override;
  31. destructor Destroy; override;
  32. function GetDummyOrientation: TDummy;
  33. function GetCamera: TCamera;
  34. function GetPositionDirection: TDummy;
  35. published
  36. property PositionCameraThirdPerson: TPoint3D read GetPositionCamera
  37. write SetPositionCamera;
  38. property AngleOfView: single read GetAngleOfView write SetAngleOfView;
  39. property TypePosition: TGBETypePosition read fTypePosition
  40. write SetTypePosition;
  41. property NextPosition: TDummy read fNextPosition write fNextPosition;
  42. property HitTest default False;
  43. property Width: single read fWidth write SetWidth;
  44. property Height: single read fHeight write SetHeight;
  45. property Depth: single read fDepth write SetDepth;
  46. end;
  47. procedure Register;
  48. implementation // --------------------------------------------------------------
  49. // TGBEPlayerPosition
  50. constructor TGBEPlayerPosition.Create(AOwner: TComponent);
  51. begin
  52. inherited;
  53. fDummyOrientation := TDummy.Create(Self);
  54. fDummyOrientation.Locked := true;
  55. fDummyOrientation.Stored := False;
  56. fDummyOrientation.Width := Self.Width;
  57. fDummyOrientation.Height := Self.Height;
  58. fDummyOrientation.Depth := Self.Depth;
  59. AddObject(fDummyOrientation);
  60. fCamera := TCamera.Create(Self);
  61. fCamera.Parent := fDummyOrientation;
  62. fNextPosition := TDummy.Create(Self);
  63. fNextPosition.Locked := true;
  64. fNextPosition.Stored := False;
  65. fNextPosition.Width := Self.Width;
  66. fNextPosition.Height := Self.Height;
  67. fNextPosition.Depth := Self.Depth;
  68. fPositionDirection := TDummy.Create(Self);
  69. fPositionDirection.Locked := true;
  70. fPositionDirection.Stored := False;
  71. fPositionDirection.Width := Self.Width;
  72. fPositionDirection.Height := Self.Height;
  73. fPositionDirection.Depth := Self.Depth;
  74. fPositionDirection.Parent := fDummyOrientation;
  75. fPositionDirection.position.X := 0;
  76. fPositionDirection.position.Y := 0;
  77. fPositionDirection.position.Z := -0.01;
  78. fTypePosition := TGBETypePosition.thirdPerson;
  79. end;
  80. destructor TGBEPlayerPosition.Destroy;
  81. begin
  82. DoDeleteChildren;
  83. inherited;
  84. end;
  85. function TGBEPlayerPosition.GetAngleOfView: single;
  86. begin
  87. result := fCamera.AngleOfView;
  88. end;
  89. function TGBEPlayerPosition.GetCamera: TCamera;
  90. begin
  91. result := fCamera;
  92. end;
  93. function TGBEPlayerPosition.GetPositionDirection: TDummy;
  94. begin
  95. result := fPositionDirection;
  96. end;
  97. function TGBEPlayerPosition.GetDummyOrientation: TDummy;
  98. begin
  99. result := fDummyOrientation;
  100. end;
  101. function TGBEPlayerPosition.GetPositionCamera: TPoint3D;
  102. begin
  103. result := fCamera.position.Point;
  104. end;
  105. procedure TGBEPlayerPosition.SetAngleOfView(const Value: single);
  106. begin
  107. fCamera.AngleOfView := Value;
  108. end;
  109. procedure TGBEPlayerPosition.SetDepth(const Value: single);
  110. begin
  111. fDepth := Value;
  112. fDummyOrientation.Depth := Value;
  113. fNextPosition.Depth := Value;
  114. fPositionDirection.Depth := Value;
  115. end;
  116. procedure TGBEPlayerPosition.SetHeight(const Value: single);
  117. begin
  118. fHeight := Value;
  119. fDummyOrientation.Height := Value;
  120. fNextPosition.Height := Value;
  121. fPositionDirection.Height := Value;
  122. end;
  123. procedure TGBEPlayerPosition.SetPositionCamera(const Value: TPoint3D);
  124. begin
  125. fCamera.position.Point := Value;
  126. end;
  127. procedure TGBEPlayerPosition.SetTypePosition(const Value: TGBETypePosition);
  128. begin
  129. fTypePosition := Value;
  130. case Value of
  131. firstPerson:
  132. begin
  133. fCamera.position.Point := Point3D(0, 0, 0);
  134. fCamera.Target := nil;
  135. end;
  136. thirdPerson:
  137. begin
  138. fCamera.position.Point := Point3D(0, -1, -3);
  139. fCamera.Target := Self;
  140. end;
  141. other:
  142. begin
  143. fCamera.Target := nil;
  144. end;
  145. end;
  146. end;
  147. procedure TGBEPlayerPosition.SetWidth(const Value: single);
  148. begin
  149. fWidth := Value;
  150. fDummyOrientation.Width := Value;
  151. fNextPosition.Width := Value;
  152. fPositionDirection.Width := Value;
  153. end;
  154. procedure Register;
  155. begin
  156. RegisterComponents('GXScene GBE', [TGBEPlayerPosition]);
  157. end;
  158. end.