Unit1.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // ---------------------------------------------------------------------------
  2. #include <system.hpp>
  3. #include <vcl.h>
  4. #include <math.h>
  5. #include <tchar.h>
  6. #pragma hdrstop
  7. #include "Unit1.h"
  8. // ---------------------------------------------------------------------------
  9. #pragma package(smart_init)
  10. #pragma link "GLS.BitmapFont"
  11. #pragma link "GLS.Cadencer"
  12. #pragma link "GLS.Coordinates"
  13. #pragma link "GLS.GeomObjects"
  14. #pragma link "GLS.HUDObjects"
  15. #pragma link "GLS.Material"
  16. #pragma link "GLS.Objects"
  17. #pragma link "GLS.Scene"
  18. #pragma link "GLS.ShadowPlane"
  19. #pragma link "GLS.Sound"
  20. #pragma link "GLS.VectorFileObjects"
  21. #pragma link "GLS.SceneViewer"
  22. #pragma link "GLS.WindowsFont"
  23. #pragma link "GLS.ScreenSaver"
  24. #pragma link "GLSM.BASS"
  25. #pragma link "GLS.File3DS"
  26. #pragma link "GLS.FileWAV"
  27. #pragma link "GLS.ScreenSaver"
  28. #pragma link "GLS.ThorFX"
  29. #pragma link "GLS.FireFX"
  30. #pragma link "GLS.Coordinates"
  31. #pragma link "GLS.FileWAV"
  32. #pragma link "GLS.LensFlare"
  33. #pragma link "GLS.ParticleFX"
  34. #pragma resource "*.dfm"
  35. TForm1 *Form1;
  36. // ---------------------------------------------------------------------------
  37. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
  38. }
  39. // ---------------------------------------------------------------------------
  40. void __fastcall TForm1::FormCreate(TObject *Sender) {
  41. String DataPath;
  42. Randomize();
  43. DataPath = ExtractFilePath(ParamStr(0)) + "data";
  44. SetCurrentDir(DataPath);
  45. FFFirTree->LoadFromFile("firtree.3ds");
  46. FFFirePlace->LoadFromFile("fireplace.3ds");
  47. fireLight = 0.5;
  48. FTYear->Text = "";
  49. }
  50. // ---------------------------------------------------------------------------
  51. void __fastcall TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button,
  52. TShiftState Shift, int X, int Y) {
  53. mx = X;
  54. my = Y;
  55. }
  56. // ---------------------------------------------------------------------------
  57. void __fastcall TForm1::ViewerMouseMove(TObject *Sender, TShiftState Shift,
  58. int X, int Y) {
  59. if (Shift.Contains(ssLeft)) {
  60. Camera->MoveAroundTarget(my - Y, mx - X);
  61. mx = X;
  62. my = Y;
  63. }
  64. }
  65. // ---------------------------------------------------------------------------
  66. void __fastcall TForm1::TimerTimer(TObject *Sender) {
  67. int i;
  68. TDateTime t;
  69. String buf;
  70. Word y, m, d;
  71. Caption = Format("%.1f FPS", ARRAYOFCONST((Viewer->FramesPerSecond())));
  72. Viewer->ResetPerformanceMonitor();
  73. if ((GLSMBASS->Active) && (bStream == 0)) {
  74. bStream = BASS_StreamCreateFile(false, PAnsiChar("Jingle_Bells_64.mp3"),
  75. 0, 0, BASS_STREAM_AUTOFREE);
  76. BASS_ChannelPlay(bStream, false);
  77. }
  78. DecodeDate(Now(), y, m, d);
  79. /// t = EncodeDate(y, 12, 25) - Now(); //Merry Christmas
  80. ///t = EncodeDate(y+1, 01, 01) - Now(); //Happy New Year!
  81. if (miMerryCristmas->Checked) {
  82. t = EncodeDate(y, 12, 25) - Now();
  83. FTCongratulations->Text = "Merry Christmas!";
  84. }
  85. else {
  86. t = EncodeDate(y + 1, 01, 01) - Now();
  87. FTCongratulations->Text = "Happy New Year!";
  88. FTYear->Text = IntToStr(y + 1);
  89. }
  90. if ((double)t < 0)
  91. FTCountDown->Text = "Merry Christmas!";
  92. if (((double)t < 1) && ((double)t > -1))
  93. DCGifts->Visible = true;
  94. if ((double)t >= 2) {
  95. buf = IntToStr(Floor((double)t)) + " days, ";
  96. i = (Int)(Frac((double)t) * 24);
  97. if (i > 1)
  98. buf = buf + IntToStr(i) + " hours...";
  99. else
  100. buf = buf + IntToStr(i) + " hour...";
  101. FTCountDown->Text = buf;
  102. }
  103. else {
  104. t = (double)t * 24;
  105. if ((double)t > 1) {
  106. buf = IntToStr((int)t) + " hours, ";
  107. i = RoundInt(Frac((double)t) * 60);
  108. if (i > 1)
  109. buf = buf + IntToStr(i) + " minutes...";
  110. else
  111. buf = buf + IntToStr(i) + " minute...";
  112. FTCountDown->Text = buf;
  113. }
  114. else {
  115. t = (double)t * 60;
  116. i = RoundInt(((double)t - Floor(t)) * 60);
  117. FTCountDown->Text = IntToStr((int)t) + " minutes, " +
  118. IntToStr(i) + " seconds...";
  119. }
  120. }
  121. }
  122. // ---------------------------------------------------------------------------
  123. void __fastcall TForm1::CadencerProgress(TObject *Sender,
  124. const double deltaTime, const double newTime) {
  125. fireLight = ClampValue(fireLight + Random() * 0.4 - 0.2, 0, 1);
  126. LSFire->Diffuse->Color = VectorLerp(clrYellow, VectorMake(0.5, 0, 0, 1),
  127. fireLight);
  128. LSFire->Position->Y = fireLight * 0.1;
  129. if (inPreview)
  130. HUDSprite->Visible = false;
  131. if (Visible) {
  132. HUDSprite->Material->FrontProperties->Diffuse->Alpha =
  133. HUDSprite->Material->FrontProperties->Diffuse->Alpha -
  134. deltaTime * 0.05;
  135. if (HUDSprite->Material->FrontProperties->Diffuse->Alpha < 0.01)
  136. HUDSprite->Visible = false;
  137. }
  138. DCFirTree->Turn(deltaTime);
  139. Viewer->Invalidate();
  140. }
  141. // ---------------------------------------------------------------------------
  142. void __fastcall TForm1::FormResize(TObject *Sender) {
  143. Camera->SceneScale = (float)Width / 640;
  144. if (Visible)
  145. HUDSprite->Position->X = Width - 200;
  146. if (Width >= Screen->Width)
  147. ViewerDblClick(Sender);
  148. }
  149. // ---------------------------------------------------------------------------
  150. void __fastcall TForm1::miMerryCristmasClick(TObject *Sender) {
  151. miMerryCristmas->Checked = True;
  152. miHappyNewYear->Checked = False;
  153. FTYear->Text = "";
  154. }
  155. // ---------------------------------------------------------------------------
  156. void __fastcall TForm1::miHappyNewYearClick(TObject *Sender) {
  157. miHappyNewYear->Checked = True;
  158. miMerryCristmas->Checked = False;
  159. }
  160. // ---------------------------------------------------------------------------
  161. void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &Key) {
  162. Key = '\0';
  163. Application->Terminate();
  164. }
  165. // ---------------------------------------------------------------------------
  166. void __fastcall TForm1::ViewerDblClick(TObject *Sender) {
  167. if ((!inPreview) && (!inSaver) && (!Application->Terminated) &&
  168. (BorderStyle != bsNone)) {
  169. BorderStyle = bsNone;
  170. FormStyle = fsStayOnTop;
  171. Align = alClient;
  172. }
  173. }
  174. // ---------------------------------------------------------------------------
  175. void __fastcall TForm1::ScreenSaverCloseQuery(TObject *Sender, bool &CanClose)
  176. {
  177. Application->Terminate();
  178. CanClose = false;
  179. }
  180. // ---------------------------------------------------------------------------
  181. void __fastcall TForm1::ScreenSaverExecute(TObject *Sender) {
  182. inSaver = true;
  183. }
  184. // ---------------------------------------------------------------------------
  185. void __fastcall TForm1::ScreenSaverPreview(TObject *Sender, HWND previewHwnd) {
  186. inPreview = true;
  187. }
  188. // ---------------------------------------------------------------------------
  189. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  190. TPoint &MousePos, bool &Handled)
  191. {
  192. Camera->AdjustDistanceToTarget(Power(1.1, WheelDelta/120));
  193. }
  194. //---------------------------------------------------------------------------