fActorProxyC.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fActorProxyC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Material"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.ProxyObjects"
  14. #pragma link "GLS.Scene"
  15. #pragma link "GLS.VectorFileObjects"
  16. #pragma link "GLS.SceneViewer"
  17. #pragma link "GLS.FileSMD"
  18. #pragma link "GLS.BaseClasses"
  19. #pragma resource "*.dfm"
  20. TFormActorProxy *FormActorProxy;
  21. //---------------------------------------------------------------------------
  22. __fastcall TFormActorProxy::TFormActorProxy(TComponent* Owner)
  23. : TForm(Owner)
  24. {
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TFormActorProxy::FormCreate(TObject *Sender)
  28. {
  29. int i;
  30. TFileName Path = GetCurrentAssetPath();
  31. SetCurrentDir(Path + "\\modelext");
  32. MasterActor->LoadFromFile("TRINITYrage.smd");
  33. MasterActor->AddDataFromFile("run.smd");
  34. MasterActor->AddDataFromFile("jump.smd");
  35. MasterActor->Animations->Items[0]->Name = "still";
  36. MasterActor->Animations->Items[1]->Name = "walk";
  37. MasterActor->Animations->Items[2]->Name = "jump";
  38. for (i = 0; i < MasterActor->Animations->Count-1; i++)
  39. {
  40. MasterActor->Animations->Items[i]->MakeSkeletalTranslationStatic();
  41. MasterActor->SwitchToAnimation(i); // forces animations to be initialized for ActorsProxies
  42. }
  43. MasterActor->SwitchToAnimation(0); // revert back to empty animation (not necessary)
  44. MasterActor->AnimationMode = aamLoop; // animationmode is shared between proxies.
  45. GLActorProxy1->StoreBonesMatrix = true;
  46. GLActorProxy2->StoreBonesMatrix = true;
  47. GLActorProxy1->Animation = MasterActor->Animations->Items[1]->Name;
  48. GLActorProxy2->Animation = MasterActor->Animations->Items[2]->Name;
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TFormActorProxy::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  52. int X, int Y)
  53. {
  54. mouseX = X;
  55. mouseY = Y;
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TFormActorProxy::DoRaycastStuff()
  59. {
  60. TGLVector rayStart;
  61. TGLVector rayVector;
  62. TGLVector iPoint;
  63. TGLVector iNormal;
  64. SetVector(rayStart, GLCamera1->AbsolutePosition);
  65. SetVector(rayVector, GLSceneViewer1->Buffer->ScreenToVector(
  66. AffineVectorMake(mouseX, GLSceneViewer1->Height-mouseY, 0)));
  67. NormalizeVector(rayVector);
  68. if (GLActorProxy1->RayCastIntersect(
  69. rayStart, rayVector, &iPoint, &iNormal))
  70. {
  71. GLSphere1->Position->AsVector = iPoint;
  72. GLSphere1->Direction->AsVector = VectorNormalize(iNormal);
  73. }
  74. else
  75. if (GLActorProxy2->RayCastIntersect(rayStart,rayVector,&iPoint,&iNormal))
  76. {
  77. GLSphere1->Position->AsVector = iPoint;
  78. GLSphere1->Direction->AsVector = VectorNormalize(iNormal);
  79. }
  80. else
  81. {
  82. GLSphere1->Position->AsVector = rayStart;
  83. GLSphere1->Direction->AsVector = rayVector;
  84. }
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TFormActorProxy::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  88. const double newTime)
  89. {
  90. // Align object to hand
  91. *GLArrowLine1->Matrix = GLActorProxy1->BoneMatrix("Bip01 R Finger1");
  92. *GLArrowLine2->Matrix = GLActorProxy2->BoneMatrix("Bip01 R Finger1");
  93. // turn actors
  94. if (chbActorsAreTurning->Checked) {
  95. GLActorProxy1->Turn(-deltaTime * 130);
  96. GLActorProxy2->Turn(deltaTime * 100);
  97. }
  98. // show master actor
  99. dcInvisible->Visible = chbShowMasterActor->Checked;
  100. DoRaycastStuff();
  101. }
  102. void __fastcall TFormActorProxy::Timer1Timer(TObject *Sender)
  103. {
  104. Panel1->Caption = GLSceneViewer1->FramesPerSecondText(0);
  105. GLSceneViewer1->ResetPerformanceMonitor();
  106. }
  107. //---------------------------------------------------------------------------