Unit1.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLBaseClasses"
  8. #pragma link "GLCadencer"
  9. #pragma link "GLCoordinates"
  10. #pragma link "GLCrossPlatform"
  11. #pragma link "GLGeomObjects"
  12. #pragma link "GLMaterial"
  13. #pragma link "GLObjects"
  14. #pragma link "GLProxyObjects"
  15. #pragma link "GLScene"
  16. #pragma link "GLVectorFileObjects"
  17. #pragma link "GLWin32Viewer"
  18. #pragma link "GLFileSMD"
  19. #pragma link "GLBaseClasses"
  20. #pragma resource "*.dfm"
  21. TForm1 *Form1;
  22. //---------------------------------------------------------------------------
  23. __fastcall TForm1::TForm1(TComponent* Owner)
  24. : TForm(Owner)
  25. {
  26. }
  27. //---------------------------------------------------------------------------
  28. void __fastcall TForm1::FormCreate(TObject *Sender)
  29. {
  30. int i;
  31. SetGLSceneMediaDir();
  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 TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  52. int X, int Y)
  53. {
  54. mouseX = X;
  55. mouseY = Y;
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TForm1::DoRaycastStuff()
  59. {
  60. Glvectorgeometry::TVector rayStart, rayVector, iPoint, iNormal;
  61. SetVector(rayStart, GLCamera1->AbsolutePosition);
  62. SetVector(rayVector, GLSceneViewer1->Buffer->ScreenToVector(
  63. AffineVectorMake(mouseX, GLSceneViewer1->Height-mouseY, 0)));
  64. NormalizeVector(rayVector);
  65. if (GLActorProxy1->RayCastIntersect(
  66. rayStart, rayVector, &iPoint, &iNormal))
  67. {
  68. GLSphere1->Position->AsVector = iPoint;
  69. GLSphere1->Direction->AsVector = VectorNormalize(iNormal);
  70. }
  71. else
  72. if (GLActorProxy2->RayCastIntersect(rayStart,rayVector,&iPoint,&iNormal))
  73. {
  74. GLSphere1->Position->AsVector = iPoint;
  75. GLSphere1->Direction->AsVector = VectorNormalize(iNormal);
  76. }
  77. else
  78. {
  79. GLSphere1->Position->AsVector = rayStart;
  80. GLSphere1->Direction->AsVector = rayVector;
  81. }
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  85. const double newTime)
  86. {
  87. // Align object to hand
  88. GLArrowLine1->Matrix = GLActorProxy1->BoneMatrix("Bip01 R Finger1");
  89. GLArrowLine2->Matrix = GLActorProxy2->BoneMatrix("Bip01 R Finger1");
  90. // turn actors
  91. if (cbActorsAreTurning->Checked)
  92. {
  93. GLActorProxy1->Turn(-deltaTime *130);
  94. GLActorProxy2->Turn(deltaTime *100);
  95. }
  96. DoRaycastStuff();
  97. }
  98. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  99. {
  100. Panel1->Caption = GLSceneViewer1->FramesPerSecondText(0);
  101. GLSceneViewer1->ResetPerformanceMonitor();
  102. }
  103. //---------------------------------------------------------------------------