fActorProxy.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. unit fActorProxy;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Variants,
  7. System.Classes,
  8. Vcl.Graphics,
  9. Vcl.Controls,
  10. Vcl.Forms,
  11. Vcl.Dialogs,
  12. Vcl.ExtCtrls,
  13. Vcl.StdCtrls,
  14. Vcl.Imaging.Jpeg,
  15. GLS.Scene,
  16. GLS.VectorTypes,
  17. GLS.SceneViewer,
  18. GLS.VectorFileObjects,
  19. GLS.Objects,
  20. GLS.ProxyObjects,
  21. GLS.GeomObjects,
  22. GLS.VectorGeometry,
  23. GLS.Cadencer,
  24. GLS.Texture,
  25. GLS.Material,
  26. GLS.Coordinates,
  27. GLS.BaseClasses,
  28. GLS.Utils,
  29. GLS.FileSMD;
  30. type
  31. TFormActorProxy = class(TForm)
  32. GLScene1: TGLScene;
  33. GLSceneViewer1: TGLSceneViewer;
  34. GLMaterialLibrary1: TGLMaterialLibrary;
  35. GLCadencer1: TGLCadencer;
  36. GLCamera1: TGLCamera;
  37. InvisibleDummyCube: TGLDummyCube;
  38. GLDummyCube2: TGLDummyCube;
  39. MasterActor: TGLActor;
  40. GLActorProxy1: TGLActorProxy;
  41. GLArrowLine1: TGLArrowLine;
  42. GLLightSource1: TGLLightSource;
  43. Timer1: TTimer;
  44. GLSphere1: TGLSphere;
  45. GLArrowLine3: TGLArrowLine;
  46. GLActorProxy2: TGLActorProxy;
  47. GLArrowLine2: TGLArrowLine;
  48. Panel1: TPanel;
  49. cbActorsAreTurning: TCheckBox;
  50. procedure FormCreate(Sender: TObject);
  51. procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
  52. newTime: Double);
  53. procedure Timer1Timer(Sender: TObject);
  54. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
  55. Y: Integer);
  56. private
  57. mouseX, mouseY : Integer;
  58. procedure DoRaycastStuff;
  59. public
  60. end;
  61. var
  62. FormActorProxy: TFormActorProxy;
  63. implementation
  64. {$R *.dfm}
  65. procedure TFormActorProxy.FormCreate(Sender: TObject);
  66. var
  67. i : Integer;
  68. begin
  69. SetGLSceneMediaDir();
  70. MasterActor.LoadFromFile('TRINITYrage.smd');
  71. MasterActor.AddDataFromFile('run.smd');
  72. MasterActor.AddDataFromFile('jump.smd');
  73. MasterActor.Animations.Items[0].Name:='still';
  74. MasterActor.Animations.Items[1].Name:='walk';
  75. MasterActor.Animations.Items[2].Name:='jump';
  76. for i := 0 to MasterActor.Animations.Count-1 do
  77. begin
  78. MasterActor.Animations[i].MakeSkeletalTranslationStatic;
  79. MasterActor.SwitchToAnimation(i); // forces animations to be initialized for ActorsProxies
  80. end;
  81. MasterActor.SwitchToAnimation(0); // revert back to empty animation (not necessary)
  82. MasterActor.AnimationMode:=aamLoop; // animationmode is shared between proxies.
  83. GLActorProxy1.StoreBonesMatrix:=true;
  84. GLActorProxy2.StoreBonesMatrix:=true;
  85. GLActorProxy1.Animation := MasterActor.Animations[1].Name;
  86. GLActorProxy2.Animation := MasterActor.Animations[2].Name;
  87. end;
  88. procedure TFormActorProxy.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
  89. Y: Integer);
  90. begin
  91. mouseX := X;
  92. mouseY := Y;
  93. end;
  94. procedure TFormActorProxy.DoRaycastStuff;
  95. var
  96. rayStart, rayVector, iPoint, iNormal : TGLVector;
  97. begin
  98. SetVector(rayStart, GLCamera1.AbsolutePosition);
  99. SetVector(rayVector, GLSceneViewer1.Buffer.ScreenToVector(
  100. AffineVectorMake(mouseX, GLSceneViewer1.Height-mouseY, 0)));
  101. NormalizeVector(rayVector);
  102. if GLActorProxy1.RayCastIntersect(rayStart,rayVector,@iPoint,@iNormal) then
  103. begin
  104. GLSphere1.Position.AsVector:=iPoint;
  105. GLSphere1.Direction.AsVector:=VectorNormalize(iNormal);
  106. end
  107. else
  108. if GLActorProxy2.RayCastIntersect(rayStart,rayVector,@iPoint,@iNormal) then
  109. begin
  110. GLSphere1.Position.AsVector:=iPoint;
  111. GLSphere1.Direction.AsVector:=VectorNormalize(iNormal);
  112. end
  113. else
  114. begin
  115. GLSphere1.Position.AsVector:=rayStart;
  116. GLSphere1.Direction.AsVector:=rayVector;
  117. end;
  118. end;
  119. procedure TFormActorProxy.GLCadencer1Progress(Sender: TObject; const deltaTime,
  120. newTime: Double);
  121. begin
  122. // Align object to hand
  123. GLArrowLine1.Matrix^ := GLActorProxy1.BoneMatrix('Bip01 R Finger1');
  124. GLArrowLine2.Matrix^ := GLActorProxy2.BoneMatrix('Bip01 R Finger1');
  125. // turn actors
  126. if cbActorsAreTurning.Checked then
  127. begin
  128. GLActorProxy1.Turn(-deltaTime *130);
  129. GLActorProxy2.Turn(deltaTime *100);
  130. end;
  131. DoRaycastStuff;
  132. end;
  133. procedure TFormActorProxy.Timer1Timer(Sender: TObject);
  134. begin
  135. Panel1.Caption:=GLSceneViewer1.FramesPerSecondText(0);
  136. GLSceneViewer1.ResetPerformanceMonitor;
  137. end;
  138. end.