Unit1.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "Unit1.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. TGLSprite *spr;
  27. String MediaPath = ExtractFilePath(ParamStr(0));
  28. int I = MediaPath.Pos("Demos");
  29. if (I != 0) {
  30. MediaPath.Delete(I+5, MediaPath.Length() - (I+5));
  31. MediaPath += "Media\\";
  32. SetCurrentDir(MediaPath);
  33. }
  34. Sprite1->Material->Texture->Image->LoadFromFile(MediaPath+"Flare1.bmp");
  35. GLMaterialLibrary1->TexturePaths = MediaPath;
  36. GLMaterialLibrary1->Materials->Items[0]->Material->Texture->Image->LoadFromFile("Flare1.bmp");
  37. // New sprites are created by duplicating the template "sprite2"
  38. for (int i = 1; i < 9; i++) {
  39. spr = (TGLSprite*)GLDummyCube1->AddNewChild(__classid(TGLSprite));
  40. spr->Assign(Sprite2);
  41. }
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  45. const double newTime)
  46. {
  47. int i;
  48. double a, aBase;
  49. // angular reference : 90° per second <=> 4 second per revolution
  50. aBase = 90*newTime;
  51. // "pulse" the star
  52. a = DegToRad(aBase);
  53. Sprite1->SetSquareSize(4+0.2*cos(3.5*a));
  54. // rotate the sprites around the yellow "star"
  55. for (i = 0; i < GLDummyCube1->Count-1; i++) {
  56. a = DegToRad(aBase+i*8);
  57. // rotation movement
  58. GLDummyCube1->Children[i]->Position->X = 4*cos(a);
  59. GLDummyCube1->Children[i]->Position->Z = 4*sin(a);
  60. // ondulation
  61. GLDummyCube1->Children[i]->Position->Y = 2*cos(2.1*a);
  62. // sprite size change
  63. Sprite1->SetSquareSize(2+cos(3*a));
  64. }
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::FormResize(TObject *Sender)
  68. {
  69. // This lines take cares of auto-zooming.
  70. // magic numbers explanation :
  71. // 333 is a form width where things looks good when focal length is 50,
  72. // ie. when form width is 333, uses 50 as focal length,
  73. // when form is 666, uses 100, etc...
  74. GLCamera1->FocalLength = Width*50/333;
  75. }
  76. //---------------------------------------------------------------------------