fActorC.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fActorC.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.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.VectorFileObjects"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma link "GLS.FileMD2"
  16. #pragma resource "*.dfm"
  17. TFormActor *FormActor;
  18. int mdx, mdy;
  19. //---------------------------------------------------------------------------
  20. __fastcall TFormActor::TFormActor(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TFormActor::FormCreate(TObject *Sender)
  26. {
  27. TFileName Path = GetCurrentAssetPath();
  28. SetCurrentDir(Path + "\\texture");
  29. // Load Texture of ground disk for Persistant Image
  30. Disk1->Material->Texture->Image->LoadFromFile("clover.jpg");
  31. Disk1->Material->Texture->Disabled = false;
  32. // Loading Actor with textures and aninations
  33. SetCurrentDir(Path + "\\modelext");
  34. Actor1->LoadFromFile("waste.md2"); // and to load a weapon later
  35. Actor1->Material->Texture->Image->LoadFromFile("waste.jpg");
  36. Actor2->Material->Texture->Image->LoadFromFile("WeaponWaste.jpg");
  37. /*
  38. Load Quake2 animations defaults, for "waste.md2", this is not required
  39. since the author did not renamed the frames, and thus, GLScene can
  40. recover them from the .MD2, but other authors just made a mess...
  41. Loading the default animations takes care of that
  42. */
  43. Actor1->Animations->LoadFromFile("Quake2Animations.aaf");
  44. // Scale Actor for put in the Scene
  45. Actor1->Scale->SetVector(0.04, 0.04, 0.04, 0);
  46. // Send animation names to the combo, to allow user selection
  47. Actor1->Animations->SetToStrings(CBAnimations->Items);
  48. // Force state to stand (first in list)
  49. CBAnimations->ItemIndex = 0;
  50. CBAnimationsChange(this); // Sender may be used
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TFormActor::SBPlayClick(TObject *Sender)
  54. {
  55. // start playing
  56. Actor1->AnimationMode = aamLoop;
  57. Actor2->AnimationMode = aamLoop;
  58. // update buttons
  59. SBPlay->Enabled = False;
  60. SBStop->Enabled = True;
  61. SBFrameToFrame->Enabled = False;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TFormActor::SBStopClick(TObject *Sender)
  65. {
  66. // stop playing
  67. Actor1->AnimationMode = aamNone;
  68. Actor2->AnimationMode = aamNone;
  69. // update buttons
  70. SBPlay->Enabled = True;
  71. SBStop->Enabled = False;
  72. SBFrameToFrame->Enabled = True;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TFormActor::CBAnimationsChange(TObject *Sender)
  76. {
  77. // Change animation
  78. Actor1->SwitchToAnimation(CBAnimations->Text, True);
  79. /*
  80. Normally actors for Quake II Model have one number of frames
  81. for all states 198 for actors and 172 for weapon,
  82. frames 173 to 198 are for death
  83. I use this for Hide and show weapon.
  84. */
  85. Actor2->Visible = (Actor1->NextFrameIndex()<173);
  86. if (Actor2->Visible)
  87. Actor2->Synchronize(Actor1);
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TFormActor::SBFrameToFrameClick(TObject *Sender)
  91. {
  92. // Animate Frame to Frame
  93. Actor1->NextFrame();
  94. Actor2->NextFrame();
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TFormActor::BBLoadWeaponClick(TObject *Sender)
  98. {
  99. // Load weapon model and texture
  100. Actor2->LoadFromFile("WeaponWaste.md2");
  101. // Get animations frames from the main actor
  102. Actor2->Animations->Assign(Actor1->Animations);
  103. // Synch both actors
  104. Actor2->Synchronize(Actor1);
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TFormActor::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  108. TShiftState Shift, int X, int Y)
  109. {
  110. // store mouse coordinates when a button went down
  111. mdx = X; mdy = Y;
  112. }
  113. //---------------------------------------------------------------------------
  114. void __fastcall TFormActor::Timer1Timer(TObject *Sender)
  115. {
  116. LabelFPS->Caption = GLSceneViewer1->FramesPerSecond();
  117. GLSceneViewer1->ResetPerformanceMonitor();
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TFormActor::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  121. int X, int Y)
  122. {
  123. // (we're moving around the parent and target dummycube)
  124. if (Shift.Contains(ssLeft))
  125. GLCamera1->MoveAroundTarget(mdy-Y, mdx-X);
  126. mdx = X; mdy = Y;
  127. }
  128. //---------------------------------------------------------------------------