Unit1.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <math.h>
  4. #include <jpeg.hpp>
  5. #pragma hdrstop
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma link "GLFileMD2"
  10. #pragma resource "*.dfm"
  11. TForm1 *Form1;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent * Owner):TForm(Owner)
  14. {
  15. float r;
  16. SetGLSceneMediaDir();
  17. GLActor1->LoadFromFile("waste.md2");
  18. r = GLActor1->BoundingSphereRadius();
  19. GLActor1->Scale->SetVector(2.5 / r, 2.5 / r, 2.5 / r);
  20. GLActor1->AnimationMode = aamLoop;
  21. GLMaterialLibrary1->Materials->Items[0]->Material->Texture->Image->
  22. LoadFromFile("wastecell.jpg");
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject * Sender,
  26. TMouseButton Button,
  27. TShiftState Shift, int X, int Y)
  28. {
  29. mx = X;
  30. my = Y;
  31. lx = X;
  32. ly = Y;
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject * Sender,
  36. TShiftState Shift, int X, int Y)
  37. {
  38. mx = X;
  39. my = Y;
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TForm1::AsyncTimer1Timer(TObject * Sender)
  43. {
  44. Form1->Caption =
  45. Format("Cel Shading Demo - %.2f FPS",
  46. ARRAYOFCONST((GLSceneViewer1->FramesPerSecond())));
  47. GLSceneViewer1->ResetPerformanceMonitor();
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::GLCadencer1Progress(TObject * Sender,
  51. const double deltaTime,
  52. const double newTime)
  53. {
  54. if(IsKeyDown(VK_LBUTTON))
  55. {
  56. GLCamera1->MoveAroundTarget(ly - my, lx - mx);
  57. lx = mx;
  58. ly = my;
  59. }
  60. GLTorus1->TurnAngle = 15 * sin(newTime * 5);
  61. GLTorus1->PitchAngle = 15 * cos(newTime * 5);
  62. }
  63. //---------------------------------------------------------------------------