Unit1.cpp 4.7 KB

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