fChrismasC.cpp 6.5 KB

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