Unit1.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLBaseClasses"
  8. #pragma link "GLBitmapFont"
  9. #pragma link "GLCadencer"
  10. #pragma link "GLCoordinates"
  11. #pragma link "GLCrossPlatform"
  12. #pragma link "GLGeomObjects"
  13. #pragma link "GLObjects"
  14. #pragma link "GLPolyhedron"
  15. #pragma link "GLScene"
  16. #pragma link "GLWin32Viewer"
  17. #pragma link "GLWindowsFont"
  18. #pragma resource "*.dfm"
  19. TForm1 *Form1;
  20. //---------------------------------------------------------------------------
  21. __fastcall TForm1::TForm1(TComponent* Owner)
  22. : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  27. const double newTime)
  28. {
  29. Viewer->Invalidate();
  30. }
  31. //---------------------------------------------------------------------------
  32. void __fastcall TForm1::OptPickModeClick(TObject *Sender)
  33. {
  34. Gizmo->PickMode = (TGLGizmoPickMode)OptPickMode->ItemIndex;
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  38. int X, int Y)
  39. {
  40. mx = X;
  41. my = Y;
  42. Gizmo->ViewerMouseDown(X, Y);
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::ViewerMouseMove(TObject *Sender, TShiftState Shift, int X,
  46. int Y)
  47. {
  48. //if noMouseMotion then exit;
  49. if (Shift.Contains(ssLeft) && (Gizmo->SelectedObj == NULL))
  50. Camera->MoveAroundTarget(Y - my, mx - X);
  51. else
  52. if (Shift.Contains(ssRight) && (Gizmo->SelectedObj == NULL))
  53. {
  54. if (my > Y)
  55. Camera->AdjustDistanceToTarget(1.05);
  56. else
  57. Camera->AdjustDistanceToTarget(0.95);
  58. Gizmo->MoveCoef = Camera->DistanceToTarget() / 1000;
  59. }
  60. else
  61. Gizmo->ViewerMouseMove(X, Y);
  62. mx = X;
  63. my = Y;
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TForm1::ViewerMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
  67. int X, int Y)
  68. {
  69. Gizmo->ViewerMouseUp(X, Y);
  70. }
  71. //---------------------------------------------------------------------------
  72. // Recurse root object to fill list of pickable objects when using PickMode=pmRaycast
  73. void __fastcall TForm1::FillPickableObjectsList(TGLBaseSceneObject *root, bool doClearList)
  74. {
  75. int t;
  76. if (doClearList)
  77. Gizmo->PickableObjectsWithRayCast->Clear();
  78. for (t = 0; t < root->Count - 1; t++)
  79. {
  80. Gizmo->PickableObjectsWithRayCast->Add(&root[t]);
  81. // FillPickableObjectsList(&root[t], false); // raised exception with stack overflow
  82. }
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TForm1::FormShow(TObject *Sender)
  86. {
  87. Viewer->SetFocus();
  88. Gizmo->RootGizmo = RootGizmo;
  89. // Fill list of pickable objects when using PickMode=pmRaycast
  90. FillPickableObjectsList(GLDummyCube1, true);
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TForm1::edAutoZoomFactorKeyPress(TObject *Sender, System::WideChar &Key)
  94. {
  95. if (Key != ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ','))
  96. Key = 0;
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TForm1::CheckBox12Click(TObject *Sender)
  100. {
  101. bool Check;
  102. // (Sender as TCheckBox).Checked:=Not((Sender as TCheckBox).Checked);
  103. Check = CheckBox12->Checked;
  104. switch (CheckBox12->Tag)
  105. {
  106. case 0: Gizmo->Enabled = Check; break;
  107. case 1: Gizmo->ExcludeObjects = Check; break;
  108. case 2:
  109. {
  110. Gizmo->ForceAxis = Check;
  111. CBXAxis->Enabled = Check;
  112. break;
  113. };
  114. case 3:
  115. {
  116. Gizmo->ForceOperation = Check;
  117. CBXOperation->Enabled = Check;
  118. break;
  119. }
  120. case 4: Gizmo->ForceUniformScale = Check; break;
  121. case 5: if (Check)
  122. Gizmo->GizmoElements = Gizmo->GizmoElements << geAxisLabel;
  123. else
  124. Gizmo->GizmoElements = Gizmo->GizmoElements >> geAxisLabel;
  125. break;
  126. case 6:
  127. {
  128. if (Check)
  129. {
  130. Gizmo->GizmoElements = Gizmo->GizmoElements << geObjectInfos;
  131. CheckBox7->Enabled = Check;
  132. CheckBox8->Enabled = Check;
  133. CheckBox9->Enabled = Check;
  134. }
  135. else
  136. {
  137. Gizmo->GizmoElements = Gizmo->GizmoElements >> geObjectInfos;
  138. CheckBox7->Enabled = Check;
  139. CheckBox8->Enabled = Check;
  140. CheckBox9->Enabled = Check;
  141. }
  142. break;
  143. }
  144. case 7: Gizmo->NoZWrite = Check; break;
  145. case 8:
  146. {
  147. Gizmo->AutoZoom = Check;
  148. if (Check)
  149. {
  150. edAutoZoomFactor->Enabled = true;
  151. edZoomFactor->Enabled = false;
  152. }
  153. else
  154. {
  155. edAutoZoomFactor->Enabled = false;
  156. edZoomFactor->Enabled = true;
  157. }
  158. break;
  159. }
  160. case 9: if (Check)
  161. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels << vliName;
  162. else
  163. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels >> vliName;
  164. break;
  165. case 10: if (Check)
  166. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels << vliOperation;
  167. else
  168. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels >> vliOperation;
  169. break;
  170. case 11: if (Check)
  171. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels << vliCoords;
  172. else
  173. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels >> vliCoords;
  174. break;
  175. case 12: if (Check)
  176. Gizmo->GizmoElements = Gizmo->GizmoElements << geMove;
  177. else
  178. Gizmo->GizmoElements = Gizmo->GizmoElements >> geMove;
  179. break;
  180. case 13: if (Check)
  181. Gizmo->GizmoElements = Gizmo->GizmoElements << geRotate;
  182. else
  183. Gizmo->GizmoElements = Gizmo->GizmoElements >> geRotate;
  184. break;
  185. case 14: if (Check)
  186. Gizmo->GizmoElements = Gizmo->GizmoElements << geScale;
  187. else
  188. Gizmo->GizmoElements = Gizmo->GizmoElements >> geScale;
  189. break;
  190. default:
  191. ;
  192. }
  193. }
  194. //---------------------------------------------------------------------------
  195. void __fastcall TForm1::CBXAxisChange(TObject *Sender)
  196. {
  197. switch (CBXAxis->ItemIndex)
  198. {
  199. case 0: Gizmo->SelAxis = gaNone; break;
  200. case 1: Gizmo->SelAxis = gaX; break;
  201. case 2: Gizmo->SelAxis = gaXY; break;
  202. case 3: Gizmo->SelAxis = gaXZ; break;
  203. case 4: Gizmo->SelAxis = gaY; break;
  204. case 5: Gizmo->SelAxis = gaYZ; break;
  205. case 6: Gizmo->SelAxis = gaZ; break;
  206. default: ;
  207. }
  208. }
  209. //---------------------------------------------------------------------------
  210. void __fastcall TForm1::CBXOperationChange(TObject *Sender)
  211. {
  212. switch (CBXOperation->ItemIndex)
  213. {
  214. case 0: Gizmo->Operation = gopNone; break;
  215. case 1: Gizmo->Operation = gopMove; break;
  216. case 2: Gizmo->Operation = gopRotate; break;
  217. case 3: Gizmo->Operation = gopScale; break;
  218. default:
  219. ;
  220. }
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TForm1::edMoveCoefChange(TObject *Sender)
  224. {
  225. if (edMoveCoef->Text != "")
  226. Gizmo->MoveCoef = StrToFloatDef(edMoveCoef->Text);
  227. }
  228. //---------------------------------------------------------------------------
  229. void __fastcall TForm1::edRotateCoefChange(TObject *Sender)
  230. {
  231. if (edRotateCoef->Text != "")
  232. Gizmo->RotationCoef = StrToFloatDef(edRotateCoef->Text);
  233. }
  234. //---------------------------------------------------------------------------
  235. void __fastcall TForm1::edGizmoThicknessChange(TObject *Sender)
  236. {
  237. Gizmo->GizmoThickness = StrToFloatDef(edGizmoThickness->Text);
  238. }
  239. //---------------------------------------------------------------------------
  240. void __fastcall TForm1::edScaleCoefChange(TObject *Sender)
  241. {
  242. if (edScaleCoef->Text != "")
  243. Gizmo->ScaleCoef = StrToFloatDef(edScaleCoef->Text);
  244. }
  245. //---------------------------------------------------------------------------
  246. void __fastcall TForm1::edAutoZoomFactorChange(TObject *Sender)
  247. {
  248. if (edAutoZoomFactor->Text != "")
  249. Gizmo->AutoZoomFactor = StrToFloatDef(edAutoZoomFactor->Text);
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TForm1::edZoomFactorChange(TObject *Sender)
  253. {
  254. if (edZoomFactor->Text != "")
  255. Gizmo->ZoomFactor = StrToFloatDef(edZoomFactor->Text);
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TForm1::ColorBox1Change(TObject *Sender)
  259. {
  260. switch (ColorBox1->Tag)
  261. {
  262. case 0: {Gizmo->BoundingBoxColor->AsWinColor = ColorBox1->Selected; break;}
  263. case 1: {Gizmo->VisibleInfoLabelsColor->AsWinColor = ColorBox2->Selected; break;}
  264. case 2: {Gizmo->SelectedColor->AsWinColor = ColorBox3->Selected; break;}
  265. default:
  266. ;
  267. }
  268. }
  269. //---------------------------------------------------------------------------
  270. void __fastcall TForm1::FormCreate(TObject *Sender)
  271. {
  272. Gizmo = new TGLGizmo(this);
  273. Gizmo->LabelFont = WindowsBitmapFont;
  274. Gizmo->Viewer = Viewer;
  275. }
  276. //---------------------------------------------------------------------------
  277. void __fastcall TForm1::FormDestroy(TObject *Sender)
  278. {
  279. Gizmo->Free();
  280. }
  281. //---------------------------------------------------------------------------