fCaterpillarC.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "fCaterpillarC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.Material"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLS.SimpleNavigation"
  15. #pragma link "GLS.SceneViewer"
  16. #pragma resource "*.dfm"
  17. TForm1 *Form1;
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20. : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::FormCreate(TObject *Sender)
  25. {
  26. TFileName Path = GetCurrentAssetPath() + "\\texture\\";
  27. GLMaterialLibrary1->TexturePaths = GetCurrentDir();
  28. Sprite1->Material->Texture->Image->LoadFromFile(Path + "flare1.bmp");
  29. GLMaterialLibrary1->Materials->Items[0]->Material->Texture->Image->LoadFromFile(Path + "flare1.bmp");
  30. // New sprites are created by duplicating the template "sprite2"
  31. for (int i = 1; i < 11; i++) {
  32. spr = (TGLSprite*)GLDummyCube1->AddNewChild(__classid(TGLSprite));
  33. spr->Assign(Sprite2);
  34. }
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  38. const double newTime)
  39. {
  40. int i;
  41. double a, aBase;
  42. // angular reference : 90° per second <=> 4 second per revolution
  43. aBase = 90*newTime;
  44. // "pulse" the star
  45. a = DegToRad(aBase);
  46. Sprite1->SetSquareSize(4+0.2*cos(3.5*a));
  47. // rotate the sprites around the yellow "star"
  48. for (i = 0; i < GLDummyCube1->Count-1; i++) {
  49. a = DegToRad(aBase+i*8);
  50. // rotation movement
  51. GLDummyCube1->Children[i]->Position->X = 4*cos(a);
  52. GLDummyCube1->Children[i]->Position->Z = 4*sin(a);
  53. // ondulation
  54. GLDummyCube1->Children[i]->Position->Y = 2*cos(2.1*a);
  55. // sprite size change
  56. Sprite1->SetSquareSize(2+cos(3*a));
  57. }
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::FormResize(TObject *Sender)
  61. {
  62. // This lines take cares of auto-zooming.
  63. // magic numbers explanation :
  64. // 333 is a form width where things looks good when focal length is 50,
  65. // ie. when form width is 333, uses 50 as focal length,
  66. // when form is 666, uses 100, etc...
  67. GLCamera1->FocalLength = Width*50/333;
  68. }
  69. //---------------------------------------------------------------------------