Unit1.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.AsyncTimer"
  9. #pragma link "GLS.BaseClasses"
  10. #pragma link "GLS.BitmapFont"
  11. #pragma link "GLS.Cadencer"
  12. #pragma link "GLS.Coordinates"
  13. #pragma link "GLS.EParticleMasksManager"
  14. #pragma link "GLS.GeomObjects"
  15. #pragma link "GLS.Material"
  16. #pragma link "GLS.Objects"
  17. #pragma link "GLS.ParticleFX"
  18. #pragma link "GLS.Scene"
  19. #pragma link "GLS.SceneViewer"
  20. #pragma link "GLS.WindowsFont"
  21. #pragma resource "*.dfm"
  22. TForm1 *Form1;
  23. //---------------------------------------------------------------------------
  24. __fastcall TForm1::TForm1(TComponent* Owner)
  25. : TForm(Owner)
  26. {
  27. PlaneHeights = 5;
  28. PlaneWidths = 5;
  29. PlaneDepths = 5;
  30. PlaneOffSets = 3;
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TForm1::RefreshMask()
  34. {
  35. TRect Rect;
  36. TGLLibMaterial *Mat;
  37. char Letter;
  38. int Depth;
  39. Letter = Edit2->Text[1];
  40. Depth = StrToIntDef(Edit1->Text, 50);
  41. XPlane->Position->X = -PlaneOffSets;
  42. XPlane->Height = PlaneHeights;
  43. XPlane->Width = PlaneWidths;
  44. YPlane->Position->Y = -PlaneOffSets;
  45. YPlane->Height = PlaneHeights;
  46. YPlane->Width = PlaneWidths;
  47. ZPlane->Position->Z = -PlaneOffSets;
  48. ZPlane->Height = PlaneHeights;
  49. ZPlane->Width = PlaneWidths;
  50. Rect.Left = 0;
  51. Rect.Top = 0;
  52. Rect.Bottom = XImage->Height;
  53. Rect.Right = XImage->Width;
  54. XImage->Canvas->Font->Name = "Arial";
  55. XImage->Canvas->Font->Size = 180;
  56. XImage->Canvas->Font->Color = clWhite;
  57. XImage->Canvas->Pen->Color = clBlack;
  58. XImage->Canvas->Pen->Style = psSolid;
  59. XImage->Canvas->Brush->Color = clBlack;
  60. XImage->Canvas->Brush->Style = bsSolid;
  61. XImage->Canvas->FillRect(Rect);
  62. XImage->Canvas->TextOut(Round((XImage->Width - XImage->Canvas->TextWidth(Letter)) / 2),
  63. Round((XImage->Height - XImage->Canvas->TextHeight(Letter)) / 2), Letter);
  64. Mat = MatLib->LibMaterialByName("XMask");
  65. ((TGLPersistentImage *)Mat->Material->Texture->Image)->Picture->Bitmap->Height = XImage->Height;
  66. ((TGLPersistentImage *)Mat->Material->Texture->Image)->Picture->Bitmap->Width = XImage->Width;
  67. ((TGLPersistentImage *)Mat->Material->Texture->Image)->Picture->Bitmap->Canvas->Draw(0, 0, XImage->Picture->Graphic);
  68. // this is a very recent implementation, the ability to generate other masks from 1 mask, so it satisfies
  69. // the requirements for the particle mask manager. useful for text and making basic shapes (cylinders etc)
  70. GLEParticleMasksManager1->ParticleMaskByName("mask")->GenerateMaskFromProjection(pptXMask, pptYMask, Depth);
  71. GLEParticleMasksManager1->ParticleMaskByName("mask")->GenerateMaskFromProjection(pptXMask, pptZMask, Depth);
  72. Mat = MatLib->LibMaterialByName("YMask");
  73. YImage->Canvas->Draw(0, 0, ((TGLPersistentImage *)Mat->Material->Texture->Image)->Picture->Graphic);
  74. Mat = MatLib->LibMaterialByName("ZMask");
  75. ZImage->Canvas->Draw(0, 0, ((TGLPersistentImage *)Mat->Material->Texture->Image)->Picture->Graphic);
  76. }
  77. void __fastcall TForm1::FormCreate(TObject *Sender)
  78. {
  79. RefreshMask();
  80. Sphere->Visible = CheckBox1->Checked;
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TForm1::GLCadencerProgress(TObject *Sender, const double deltaTime,
  84. const double newTime)
  85. {
  86. Sphere->TurnAngle = -newTime * 20;
  87. Sphere->Position->X = Cos(DegToRad(newTime * 20)) * 1.5;
  88. Sphere->Position->Z = Sin(DegToRad(newTime * 20)) * 1.5;
  89. SceneViewer->Invalidate();
  90. }
  91. //---------------------------------------------------------------------------
  92. void __fastcall TForm1::SceneViewerMouseMove(TObject *Sender, TShiftState Shift, int X,
  93. int Y)
  94. {
  95. if (Shift.Contains(ssLeft))
  96. Camera->MoveAroundTarget(my - Y, mx - X);
  97. mx = X;
  98. my = Y;
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  102. TPoint &MousePos, bool &Handled)
  103. {
  104. Camera->FocalLength = Camera->FocalLength + (WheelDelta / 150);
  105. Handled = true;
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TForm1::PLManagerCreateParticle(TObject *Sender, TGLParticle *aParticle)
  109. {
  110. int i;
  111. TGLParticle *Particle;
  112. // using point lights just coz it is easier to see the effect
  113. if (PLManager->Particles->ItemCount() > 0)
  114. for (i = 0; i < PLManager->Particles->ItemCount(); i++)
  115. {
  116. Particle = PLManager->Particles->Items[i];
  117. // first we find the particles that are tagged (since before particle creation, the position is overridden)
  118. if (Particle->Tag == 1)
  119. {
  120. if (CheckBox1->Checked)
  121. GLEParticleMasksManager1->SetParticlePositionFromMaskTarget(Particle, "mask", Sphere);
  122. else
  123. GLEParticleMasksManager1->SetParticlePositionFromMask(Particle, "mask");
  124. Particle->Tag = 0;
  125. }
  126. }
  127. // we tag the new particle for when another particle is made so we know this one needs updating aswell
  128. aParticle->Tag = 1;
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  132. {
  133. Sphere->Visible = CheckBox1->Checked;
  134. }
  135. //---------------------------------------------------------------------------
  136. void __fastcall TForm1::AsyncTimer1Timer(TObject *Sender)
  137. {
  138. Caption = FormatFloat("Particle Masking - FPS: 0.0", SceneViewer->FramesPerSecond()) + " Particle Count: " + IntToStr(PLManager->ParticleCount());
  139. SceneViewer->ResetPerformanceMonitor();
  140. }
  141. //---------------------------------------------------------------------------
  142. void __fastcall TForm1::Button1Click(TObject *Sender)
  143. {
  144. Camera->Position->Z = 0;
  145. Camera->Position->Y = 0;
  146. Camera->Position->X = 4;
  147. }
  148. //---------------------------------------------------------------------------
  149. void __fastcall TForm1::Button2Click(TObject *Sender)
  150. {
  151. Camera->Position->X = 0;
  152. Camera->Position->Z = 0.01;
  153. Camera->Position->Y = 4;
  154. }
  155. //---------------------------------------------------------------------------
  156. void __fastcall TForm1::Button3Click(TObject *Sender)
  157. {
  158. Camera->Position->X = 0;
  159. Camera->Position->Y = 0;
  160. Camera->Position->Z = 4;
  161. }
  162. //---------------------------------------------------------------------------
  163. void __fastcall TForm1::Button4Click(TObject *Sender)
  164. {
  165. FormCreate(Sender);
  166. }
  167. //---------------------------------------------------------------------------
  168. void __fastcall TForm1::Edit2Change(TObject *Sender)
  169. {
  170. RefreshMask();
  171. }
  172. //---------------------------------------------------------------------------
  173. void __fastcall TForm1::Edit3Change(TObject *Sender)
  174. {
  175. GLEParticleMasksManager1->ParticleMaskByName("mask")->PitchAngle = System::Sysutils::StrToFloatDef(Edit3->Text, 0);
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TForm1::Edit4Change(TObject *Sender)
  179. {
  180. GLEParticleMasksManager1->ParticleMaskByName("mask")->RollAngle = System::Sysutils::StrToFloatDef(Edit4->Text, 0);
  181. }
  182. //---------------------------------------------------------------------------
  183. void __fastcall TForm1::Edit5Change(TObject *Sender)
  184. {
  185. GLEParticleMasksManager1->ParticleMaskByName("mask")->TurnAngle = System::Sysutils::StrToFloatDef(Edit5->Text, 0);
  186. }
  187. //---------------------------------------------------------------------------