fSkeletalC.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fSkeletalC.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.Graph"
  11. #pragma link "GLS.Material"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLS.VectorFileObjects"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma link "GLS.FileSMD"
  17. #pragma resource "*.dfm"
  18. TForm1 *Form1;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::FormCreate(TObject *Sender)
  26. {
  27. SetGLSceneMediaDir();
  28. // We load the SMD model here
  29. // Note the actor was linked to a material library, and textures are loaded
  30. // automatically (4 textures are used by this model)
  31. //
  32. // Kind thanks to ~A.u.s.t.i.n. & Neal 'Guplik' Corbett for the model
  33. // and allowing its use ;)
  34. Actor1->LoadFromFile("trinityRage.smd");
  35. // Now we load the walk & run animations and "fix" their translation
  36. // (HL walk/run animations have a built-in "slide" that we don't want here)
  37. Actor1->AddDataFromFile("walk.smd");
  38. Actor1->Animations->Items[1]->MakeSkeletalTranslationStatic();
  39. Actor1->AddDataFromFile("run.smd");
  40. Actor1->Animations->Items[2]->MakeSkeletalTranslationStatic();
  41. // Then load the two jumps
  42. Actor1->AddDataFromFile("long_jump.smd");
  43. Actor1->AddDataFromFile("jump.smd");
  44. // And the 'look_left_right' blending animations, that we immediately
  45. // assign to the controler. The MakeSkeletalRotationDelta removes absolute
  46. // information from the SMD (which HL may use, but GLScene doesn't)
  47. Actor1->AddDataFromFile("look_left_right.smd");
  48. Actor1->Animations->Items[5]->MakeSkeletalRotationDelta();
  49. AnimationControler1->AnimationName = "look_left_right";
  50. // Skeleton visible, and start with walk animation
  51. // (pseudo-animation 0 is for the static model in its default attitude)
  52. Actor1->OverlaySkeleton = true;
  53. baseAnimation = "walk";
  54. Actor1->SwitchToAnimation(baseAnimation);
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  58. TPoint &MousePos, bool &Handled)
  59. {
  60. GLCamera1 = GLSceneViewer1->Camera;
  61. GLCamera1->AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::RBWalkClick(TObject *Sender)
  65. {
  66. // user requested 'walk'
  67. baseAnimation = "walk";
  68. Actor1->SwitchToAnimation(baseAnimation, true);
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::RBRunClick(TObject *Sender)
  72. {
  73. // user requested 'run'
  74. baseAnimation = "run";
  75. Actor1->SwitchToAnimation(baseAnimation, true);
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TForm1::BULongJumpClick(TObject *Sender)
  79. {
  80. // Smoothly switch to Long Jump
  81. Actor1->SwitchToAnimation(3, true);
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::BUHighJumpClick(TObject *Sender)
  85. {
  86. // Smoothly switch to High Jump
  87. Actor1->SwitchToAnimation(4, true);
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::Actor1EndFrameReached(TObject *Sender)
  91. {
  92. // If we weren't walking, switch back to walk
  93. if (Actor1->CurrentAnimation() != baseAnimation)
  94. Actor1->SwitchToAnimation(baseAnimation, true);
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TForm1::CBBlendClick(TObject *Sender)
  98. {
  99. // Enable/disable blending by binding or unbinding the animation controler
  100. // to the actor
  101. if (CBBlend->Checked)
  102. {
  103. AnimationControler1->Actor = Actor1;
  104. TrackBar1Change(this);
  105. }
  106. else
  107. AnimationControler1->Actor = NULL;
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TForm1::TrackBar1Change(TObject *Sender)
  111. {
  112. // Blending along the controler's animation is just a matter of adjusting
  113. // the ratio, with 0 = first frame and 1 = last frame.
  114. AnimationControler1->Ratio = TrackBar1->Position*0.01;
  115. }
  116. //---------------------------------------------------------------------------
  117. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  118. {
  119. Actor1->OverlaySkeleton = CheckBox1->Checked;
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  123. TShiftState Shift, int X, int Y)
  124. {
  125. mx = X; my = Y;
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  129. int X, int Y)
  130. {
  131. if (Shift.Contains(ssLeft) || Shift.Contains(ssRight))
  132. {
  133. GLCamera1->MoveAroundTarget(my-Y, mx-X);
  134. mx = X; my = Y;
  135. }
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  139. {
  140. LabelFPS->Caption = Format("%.1f FPS",
  141. ARRAYOFCONST ((GLSceneViewer1->FramesPerSecond())));
  142. GLSceneViewer1->ResetPerformanceMonitor();
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  146. const double newTime)
  147. {
  148. GLScene1->NotifyChange(NULL);
  149. }
  150. //---------------------------------------------------------------------------