fCelShadingC.cpp 2.3 KB

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