fActorProxyD.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. unit fActorProxyD;
  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. GLScene.VectorTypes,
  17. GLS.SceneViewer,
  18. GLS.VectorFileObjects,
  19. GLS.Objects,
  20. GLS.ProxyObjects,
  21. GLS.GeomObjects,
  22. GLScene.VectorGeometry,
  23. GLS.Cadencer,
  24. GLS.Texture,
  25. GLS.Material,
  26. GLS.Coordinates,
  27. GLS.BaseClasses,
  28. GLScene.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. dcInvisible: TGLDummyCube;
  38. dcShow: 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. chbShowMasterActor: TCheckBox;
  51. procedure FormCreate(Sender: TObject);
  52. procedure GLCadencer1Progress(Sender: TObject; const deltaTime,
  53. newTime: Double);
  54. procedure Timer1Timer(Sender: TObject);
  55. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
  56. Y: Integer);
  57. private
  58. mouseX, mouseY : Integer;
  59. procedure DoRaycastStuff;
  60. public
  61. end;
  62. var
  63. FormActorProxy: TFormActorProxy;
  64. implementation
  65. {$R *.dfm}
  66. procedure TFormActorProxy.FormCreate(Sender: TObject);
  67. var
  68. i : Integer;
  69. begin
  70. var Path: TFileName := GetCurrentAssetPath();
  71. SetCurrentDir(Path + '\modelext');
  72. MasterActor.LoadFromFile('TRINITYrage.smd');
  73. MasterActor.AddDataFromFile('run.smd');
  74. MasterActor.AddDataFromFile('jump.smd');
  75. MasterActor.Animations.Items[0].Name:='still';
  76. MasterActor.Animations.Items[1].Name:='walk';
  77. MasterActor.Animations.Items[2].Name:='jump';
  78. for i := 0 to MasterActor.Animations.Count-1 do
  79. begin
  80. MasterActor.Animations[i].MakeSkeletalTranslationStatic;
  81. MasterActor.SwitchToAnimation(i); // forces animations to be initialized for ActorsProxies
  82. end;
  83. MasterActor.SwitchToAnimation(0); // revert back to empty animation (not necessary)
  84. MasterActor.AnimationMode:=aamLoop; // animationmode is shared between proxies.
  85. GLActorProxy1.StoreBonesMatrix:=true;
  86. GLActorProxy2.StoreBonesMatrix:=true;
  87. GLActorProxy1.Animation := MasterActor.Animations[1].Name;
  88. GLActorProxy2.Animation := MasterActor.Animations[2].Name;
  89. end;
  90. procedure TFormActorProxy.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState; X,
  91. Y: Integer);
  92. begin
  93. mouseX := X;
  94. mouseY := Y;
  95. end;
  96. procedure TFormActorProxy.DoRaycastStuff;
  97. var
  98. rayStart, rayVector, iPoint, iNormal : TGLVector;
  99. begin
  100. SetVector(rayStart, GLCamera1.AbsolutePosition);
  101. SetVector(rayVector, GLSceneViewer1.Buffer.ScreenToVector(
  102. AffineVectorMake(mouseX, GLSceneViewer1.Height-mouseY, 0)));
  103. NormalizeVector(rayVector);
  104. if GLActorProxy1.RayCastIntersect(rayStart,rayVector,@iPoint,@iNormal) then
  105. begin
  106. GLSphere1.Position.AsVector:=iPoint;
  107. GLSphere1.Direction.AsVector:=VectorNormalize(iNormal);
  108. end
  109. else
  110. if GLActorProxy2.RayCastIntersect(rayStart,rayVector,@iPoint,@iNormal) then
  111. begin
  112. GLSphere1.Position.AsVector:=iPoint;
  113. GLSphere1.Direction.AsVector:=VectorNormalize(iNormal);
  114. end
  115. else
  116. begin
  117. GLSphere1.Position.AsVector:=rayStart;
  118. GLSphere1.Direction.AsVector:=rayVector;
  119. end;
  120. end;
  121. procedure TFormActorProxy.GLCadencer1Progress(Sender: TObject; const deltaTime,
  122. newTime: Double);
  123. begin
  124. // Align object to hand
  125. GLArrowLine1.Matrix^ := GLActorProxy1.BoneMatrix('Bip01 R Finger1');
  126. GLArrowLine2.Matrix^ := GLActorProxy2.BoneMatrix('Bip01 R Finger1');
  127. // turn actors
  128. if cbActorsAreTurning.Checked then
  129. begin
  130. GLActorProxy1.Turn(-deltaTime *130);
  131. GLActorProxy2.Turn(deltaTime *100);
  132. end;
  133. // show master actor
  134. dcInvisible.Visible := chbShowMasterActor.Checked;
  135. DoRaycastStuff;
  136. end;
  137. procedure TFormActorProxy.Timer1Timer(Sender: TObject);
  138. begin
  139. Panel1.Caption:=GLSceneViewer1.FramesPerSecondText(0);
  140. GLSceneViewer1.ResetPerformanceMonitor;
  141. end;
  142. end.