fActorProxyC.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. TForm1 *Form1;
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm1::TForm1(TComponent* Owner)
  23. : TForm(Owner)
  24. {
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::FormCreate(TObject *Sender)
  28. {
  29. int i;
  30. SetGLSceneMediaDir();
  31. MasterActor->LoadFromFile("TRINITYrage.smd");
  32. MasterActor->AddDataFromFile("run.smd");
  33. MasterActor->AddDataFromFile("jump.smd");
  34. MasterActor->Animations->Items[0]->Name = "still";
  35. MasterActor->Animations->Items[1]->Name = "walk";
  36. MasterActor->Animations->Items[2]->Name = "jump";
  37. for (i = 0; i < MasterActor->Animations->Count-1; i++)
  38. {
  39. MasterActor->Animations->Items[i]->MakeSkeletalTranslationStatic();
  40. MasterActor->SwitchToAnimation(i); // forces animations to be initialized for ActorsProxies
  41. }
  42. MasterActor->SwitchToAnimation(0); // revert back to empty animation (not necessary)
  43. MasterActor->AnimationMode = aamLoop; // animationmode is shared between proxies.
  44. GLActorProxy1->StoreBonesMatrix = true;
  45. GLActorProxy2->StoreBonesMatrix = true;
  46. GLActorProxy1->Animation = MasterActor->Animations->Items[1]->Name;
  47. GLActorProxy2->Animation = MasterActor->Animations->Items[2]->Name;
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  51. int X, int Y)
  52. {
  53. mouseX = X;
  54. mouseY = Y;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::DoRaycastStuff()
  58. {
  59. TGLVector rayStart;
  60. TGLVector rayVector;
  61. TGLVector iPoint;
  62. TGLVector iNormal;
  63. SetVector(rayStart, GLCamera1->AbsolutePosition);
  64. SetVector(rayVector, GLSceneViewer1->Buffer->ScreenToVector(
  65. AffineVectorMake(mouseX, GLSceneViewer1->Height-mouseY, 0)));
  66. NormalizeVector(rayVector);
  67. if (GLActorProxy1->RayCastIntersect(
  68. rayStart, rayVector, &iPoint, &iNormal))
  69. {
  70. GLSphere1->Position->AsVector = iPoint;
  71. GLSphere1->Direction->AsVector = VectorNormalize(iNormal);
  72. }
  73. else
  74. if (GLActorProxy2->RayCastIntersect(rayStart,rayVector,&iPoint,&iNormal))
  75. {
  76. GLSphere1->Position->AsVector = iPoint;
  77. GLSphere1->Direction->AsVector = VectorNormalize(iNormal);
  78. }
  79. else
  80. {
  81. GLSphere1->Position->AsVector = rayStart;
  82. GLSphere1->Direction->AsVector = rayVector;
  83. }
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  87. const double newTime)
  88. {
  89. // Align object to hand
  90. * GLArrowLine1->Matrix = GLActorProxy1->BoneMatrix("Bip01 R Finger1");
  91. * GLArrowLine2->Matrix = GLActorProxy2->BoneMatrix("Bip01 R Finger1");
  92. // turn actors
  93. if (cbActorsAreTurning->Checked)
  94. {
  95. GLActorProxy1->Turn(-deltaTime *130);
  96. GLActorProxy2->Turn(deltaTime *100);
  97. }
  98. DoRaycastStuff();
  99. }
  100. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  101. {
  102. Panel1->Caption = GLSceneViewer1->FramesPerSecondText(0);
  103. GLSceneViewer1->ResetPerformanceMonitor();
  104. }
  105. //---------------------------------------------------------------------------